Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: Re: Using (s)printf()

by Anonymous Monk
on Sep 01, 2001 at 03:29 UTC ( [id://109602]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Re: Using (s)printf()
in thread Using (s)printf()

Actually, this isn't quite the whole story. Most everyone follows the IEEE convention of "round towards nearest or even."
Examples (rounding all of these to the one's place):

2.51 becomes 3 (this is the 'nearest' rule, which always comes first)
2.49 becomes 2 (again, 'nearest')

However, what happens if you have 2.50 ? Which way do you round it... 'tis no nearer to 2 than to 3. The IEEE standard says if there is a tie, round to the even number.

2.50 becomes 2
3.50 becomes 4

You have to pick up or down... this method is consistent and thus tends to make your errors (statistically) smaller.

Replies are listed 'Best First'.
Re4: Using (s)printf()
by Hofmator (Curate) on Sep 03, 2001 at 11:32 UTC

    Actually, this isn't quite the whole story. Most everyone follows the IEEE convention of "round towards nearest or even."
    I'm aware of that - but it wasn't applicable in this case. Btw, (s)printf doesn't seem to get it right:
    printf "%.15f", 0.5; # prints 0.500000000000000 printf "%.0f", 0.5; # prints 1 and should print 0
    and 0.5 can be represented exactly ...

    -- Hofmator

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://109602]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.