X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=ocaml%2Ftest_overflow.ml;fp=ocaml%2Ftest_overflow.ml;h=e9a8cf124a82867a990e583c138352bb9f134665;hb=ca6e467060deb728164f28de6f636ca1e29ac9ba;hp=0000000000000000000000000000000000000000;hpb=60a6a789a1e4dbac5373bc44a9aa005b618e3716;p=fedora-mingw.git diff --git a/ocaml/test_overflow.ml b/ocaml/test_overflow.ml new file mode 100644 index 0000000..e9a8cf1 --- /dev/null +++ b/ocaml/test_overflow.ml @@ -0,0 +1,23 @@ +(* Look for assembler errors like this: + * 'Warning: 9223372036854775807 shortened to 4294967295' + * Try to reproduce and fix. + *) + +open Printf + +let () = + let i = max_int in (* Different on 32 & 64 bit platforms.*) + printf "max_int = %d\n" i; + let i = min_int in + printf "min_int = %d\n" i; + let i64 = Int64.max_int in (* Same on all platforms. *) + printf "Int64.max_int = %Ld\n" i64; + let i32 = Int32.max_int in + printf "Int32.max_int = %ld\n" i32; + + (* This is how the stdlib computes min_int: + * min_int = 1 lsl (if 1 lsl 31 = 0 (* ie. 32 bit *) then 30 else 62) + *) + printf "1 lsl 31 = %d\n" (1 lsl 31); + printf "1 lsl 30 = %d\n" (1 lsl 30); + printf "1 lsl 62 = %d\n" (1 lsl 62)