diff options
author | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2010-10-28 14:56:39 +0000 |
---|---|---|
committer | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2010-10-28 14:56:39 +0000 |
commit | 14a9bb4b267eeead8cd9503ee19e860a8bc0d763 (patch) | |
tree | c70dda532a974a7b62969c6b199b80d65784dc91 /lib/Floataux.ml | |
parent | b54721f58c2ecb65ce554d8b34f214d5121a2b0c (diff) | |
download | compcert-14a9bb4b267eeead8cd9503ee19e860a8bc0d763.tar.gz compcert-14a9bb4b267eeead8cd9503ee19e860a8bc0d763.zip |
Float.intoffloat and Float.intuoffloat are now partial functions.
(May fail if float is too big to be converted.)
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1544 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'lib/Floataux.ml')
-rw-r--r-- | lib/Floataux.ml | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/Floataux.ml b/lib/Floataux.ml index f0db1fa0..dfdd6ce9 100644 --- a/lib/Floataux.ml +++ b/lib/Floataux.ml @@ -19,10 +19,14 @@ let singleoffloat f = Int32.float_of_bits (Int32.bits_of_float f) let intoffloat f = - coqint_of_camlint (Int32.of_float f) + if f < 2147483648.0 (*2^31 *) && f > -2147483649.0 (* -2^31-1 *) + then Some (coqint_of_camlint (Int32.of_float f)) + else None let intuoffloat f = - coqint_of_camlint (Int64.to_int32 (Int64.of_float f)) + if f < 4294967296.0 (* 2^32 *) && f >= 0.0 + then Some (coqint_of_camlint (Int64.to_int32 (Int64.of_float f))) + else None let floatofint i = Int32.to_float (camlint_of_coqint i) |