Re: Phix, numbers, printf, log10
- Posted by RobertS 2 months ago
- 689 views
Also found this:
99800000000000000 is integer
9.98 * power(10, 16) is integer -- <<== erm?
9.98e16 is not integer
You quite sure about that? ?apply({99800000000000000,9.98 * power(10, 16),9.98e16},integer) gets me {1,0,0}.
Ooops, my mistake, sorry! By mistake I tested two different values:
? integer(9.98e16)
0
? integer(9.989 * power(10, 16))
1
but, 9.989e16 is integer, too, and 9.98 * power(10, 16) is not - so, exx and power(10, xx) are consistent. There remains the (to me) mystery that 9.98e16 is not an integer, while 9.989e16 is, but I have yet to look closer at all the information you've given.
But, back to 2.85 ...
Ah, the problem here is that 2.85 cannot be held exactly, and the nearest IEEE-754 representation is ~2.849999999999999999 which is correctly rounded down. You might be able to do something with rationals, otherwise that's a fundamental and unsolveable hardware issue.
This explains why printf(1, "%0.1f\n", 2.85) says 2.8.
But, round() correctly rounds 2.85 up — printf(1, "%0.1f\n", round(2.85, 10)) says 2.9.
From what I've seen so far, round() (however it does it) may indeed solve this unsolveable issue, or haven't I tested enough and am too optimistic?
Thanks again!
Robert