Files
mercury/tests/hard_coded/from_int_int16.m
Julien Fischer 7bffc574e9 Fix a bug in uint64.cast_from_uint/1.
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.
2021-07-10 04:44:51 +10:00

63 lines
1.4 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
%---------------------------------------------------------------------------%
% Test conversion of ints to signed 16-bit integers.
:- module from_int_int16.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module int16.
:- import_module list.
:- import_module string.
%---------------------------------------------------------------------------%
main(!IO) :-
list.foldl(do_test, numbers, !IO).
:- pred do_test(int::in, io::di, io::uo) is det.
do_test(Int, !IO) :-
io.format("from_int(%d) = ", [i(Int)], !IO),
( if
int16.from_int(Int, Int16)
then
io.format("%s\n", [s(int16_to_string(Int16))], !IO)
else
io.write_string("<<out-of-range>>\n", !IO)
).
:- func numbers = list(int).
numbers = [
-2147483648,
-32769,
-32768,
-128,
0,
1,
2,
8,
10,
16,
127,
32767,
32768,
2147483647
].
%---------------------------------------------------------------------------%
:- end_module from_int_int16.
%---------------------------------------------------------------------------%