Re: Phix, numbers, printf, log10

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

%f has a "5" rounding issue, this too happens with all kinds of numbers and any number of decimal digits (also happens with Euphoria, as far as I can remember):

printf(1, "%0.1f", 2.75)
2.8
rounding up

printf(1, "%0.1f", 2.85)
2.8
rounding down

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. [At least now I can start on the first three.]

PS I stumbled on what might be a fairly nifty magnitude() function, but it needs the range of values it must cope with, from you, and probably a bit of polishing, before I can post it.

Update: I've now got a fix for the first part ("%e" was not updating f the same way "%f" does as it printed digits):

builtins\VM\pprntfN.e line ~222 said...
            digit = floor(f) 
--21/2/24: 
            f = (f-digit)*10 

and

builtins\VM\pprntfN.e line ~248 said...
--21/2/24 
--                  f = (f-digit)*10 
                    digit = floor(f) 
                    f = (f-digit)*10 

Many thanks. I'd recommend running "p -test" after editing that in and running "p -cp", to make sure nothing got broken.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu