Re: Phix, numbers, printf, log10

new topic     » goto parent     » topic index » view thread      » older message » newer message
petelomax said...
RobertS said...

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 ...

petelomax said...

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu