From: Mohamed Iguernlala <iguer.auto@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] Is this a bug in Num.float_of_num ?
Date: Thu, 26 May 2016 10:24:39 +0200 [thread overview]
Message-ID: <5746B2C7.2030608@gmail.com> (raw)
Hi,
I came to the following "stange" behavior when using the function
float_of_num. I don't know if this should be considered as a bug,
since this function has no specification (in num.mli *)
The float "f = 6004799503160661. /. 18014398509481984." has an
exact representation on 64 bits. Its value is
0.333333333333333314829616256247390992939472198486328125
However, when using float_of_num to compute the float corresponding to
the number above represented as a num, the result is slightly different.
In fact, the value returned for the expression
fnum = Num.float_of_num (Num.num_of_string
"6004799503160661/18014398509481984")
is
0.333333333333000025877623784253955818712711334228515625
I tried to investigate the reason of this difference. It seems
that it is due to the (default) value of the constant
"floating_precision"[1] in file arith_flags.ml of num library: it
is equal to 12 instead of 54 (I think) for 64bits standard floats
representation.
How should this situation be interpreted ?
(a) Should one explicitly modify the value of the
reference "floating_precision" before calling function
float_of_num ?
(b) Should the function be parametrized by a precision (which is
better than modifying global references like in (a) ) ?
(c) Other suggestion / solution ?
I attach a standalone file with relevant parts of Nums, Ratio,
Arith_flags, and Int_misc to reproduce this behavior and to
easily play with the value of "floating_precision".
Regards,
Mohamed Iguernlala.
[1]
https://github.com/ocaml/ocaml/blob/4.03.0/otherlibs/num/arith_flags.ml#L22
PS. I have not seen any constant in arith_flags.ml about the min/max
value of
the exponent ...
--
Senior R&D Engineer, OCamlPro
Research Associate, VALS team, LRI.
http://www.iguer.info
https://fr.linkedin.com/in/mohamed-iguernlala-71515979
next reply other threads:[~2016-05-26 8:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-26 8:24 Mohamed Iguernlala [this message]
2016-05-26 8:57 ` Xavier Leroy
2016-05-26 9:16 ` Mohamed Iguernlala
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5746B2C7.2030608@gmail.com \
--to=iguer.auto@gmail.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox