mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-20 11:54:02 +00:00
Add a test of uint -> uint64 conversion.
library/uint64.m:
Fix a typo that broke uint64.cast_from_uint/1.
tests/hard_coded/Mmakefile:
tests/hard_coded/from_uint_uint64.{m,exp,exp2}:
Add a test of uint -> uint64 conversion.
tests/hard_coded/from_int_int*.m:
tests/hard_coded/from_uint_uint*.m:
Fix errors in comments.
66 lines
1.5 KiB
Mathematica
66 lines
1.5 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
|
|
%---------------------------------------------------------------------------%
|
|
|
|
% Test conversion of ints to signed 32-bit integers.
|
|
|
|
:- module from_int_int32.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module int32.
|
|
|
|
:- import_module list.
|
|
:- import_module string.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
list.foldl(do_test, numbers, !IO).
|
|
|
|
:- pred do_test(string::in, io::di, io::uo) is det.
|
|
|
|
do_test(IntStr, !IO) :-
|
|
io.format("from_int(%s) = ", [s(IntStr)], !IO),
|
|
( if
|
|
string.to_int(IntStr, Int),
|
|
int32.from_int(Int, Int32)
|
|
then
|
|
io.format("%s\n", [s(int32_to_string(Int32))], !IO)
|
|
else
|
|
io.write_string("<<out-of-range>>\n", !IO)
|
|
).
|
|
|
|
:- func numbers = list(string).
|
|
|
|
numbers = [
|
|
"-9223372036854775808",
|
|
"-2147483649",
|
|
"-2147483648",
|
|
"-32768",
|
|
"-128",
|
|
"0",
|
|
"1",
|
|
"2",
|
|
"8",
|
|
"10",
|
|
"16",
|
|
"127",
|
|
"32767",
|
|
"2147483647",
|
|
"2147483648",
|
|
"9223372036854775807"
|
|
].
|
|
|
|
%---------------------------------------------------------------------------%
|
|
:- end_module from_int_int32.
|
|
%---------------------------------------------------------------------------%
|