From 73693beee1c7e4045438632f0a36f8268f729c0f Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Added two float tests which show a difference under native & cross compilers. --- .hgignore | 2 ++ ocaml/Makefile | 16 +++++++++++++++- ocaml/test_float.ml | 14 ++++++++++++++ ocaml/test_float2.ml | 7 +++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 ocaml/test_float.ml create mode 100644 ocaml/test_float2.ml diff --git a/.hgignore b/.hgignore index 745fc89..a9420f6 100644 --- a/.hgignore +++ b/.hgignore @@ -79,6 +79,8 @@ ocaml/test_format ocaml/sudoku ocaml/test_buffer ocaml/test_overflow +ocaml/test_float +ocaml/test_float2 ocaml/*.exe ocaml/*.cmi ocaml/*.cmx diff --git a/ocaml/Makefile b/ocaml/Makefile index 3a2972d..fe653ef 100644 --- a/ocaml/Makefile +++ b/ocaml/Makefile @@ -3,7 +3,8 @@ all: test1 test1.exe test2 test2.exe test3 test3.exe test4 test4.exe \ test_format test_format.exe sudoku sudoku.exe \ - test_buffer test_buffer.exe test_overflow test_overflow.exe + test_buffer test_buffer.exe test_overflow test_overflow.exe \ + test_float test_float.exe test_float2 test_float2.exe test1: test1.ml ocamlopt $< -o $@ @@ -53,6 +54,19 @@ test_overflow: test_overflow.ml test_overflow.exe: test_overflow.ml i686-pc-mingw32-ocamlopt $< -o $@ +test_float: test_float.ml + ocamlopt $< -o $@ + +test_float.exe: test_float.ml + i686-pc-mingw32-ocamlopt $< -o $@ + +test_float2: test_float2.ml + ocamlopt $< -o $@ + +test_float2.exe: test_float2.ml + i686-pc-mingw32-ocamlopt $< -o $@ + clean: rm -f test[1-4] test_format sudoku test_buffer test_overflow \ + test_float test_float2 \ *.exe *.cmi *.cmx *.o diff --git a/ocaml/test_float.ml b/ocaml/test_float.ml new file mode 100644 index 0000000..04aff8b --- /dev/null +++ b/ocaml/test_float.ml @@ -0,0 +1,14 @@ +(* Float test, part of calendar test which was failing. *) + +open Printf + +let x = 1 * 3600 + 2 * 60 + 3 ;; + +printf "minutes = %g\n" (float x /. 60.) ;; + +printf "minutes (immediate) = 62.05 is %b\n" ((float x /. 60.) = 62.05) ;; + +let m = float x /. 60. ;; + +printf "minutes (variable) = 62.05 is %b\n" (m = 62.05) ;; + diff --git a/ocaml/test_float2.ml b/ocaml/test_float2.ml new file mode 100644 index 0000000..a958984 --- /dev/null +++ b/ocaml/test_float2.ml @@ -0,0 +1,7 @@ +(* Another float/int conversion problem or difference. *) + +open Printf ;; + +printf "%d\n" (int_of_float (62.05 *. 60.)) ;; +let s = 62.05 *. 60. ;; +printf "%d\n" (int_of_float s) ;; -- 1.8.3.1