Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: May I be bitten by floating point arithmetic in the following restricted case?

by ikegami (Pope)
on Feb 23, 2010 at 18:30 UTC ( #824912=note: print w/ replies, xml ) Need Help??


in reply to May I be bitten by floating point arithmetic in the following restricted case?

As you know, a tiny error log($size) / log(2) could lead to a big error in the result. Perl Differences in the underlying C libraries and hardware can result in those tiny differences on other systems even if they don't exist on your own.

I suppose the error coming from floating point arithmetic can bite me only in the case when $size is a power of 2

You also need to check one less than powers of two for errors rounding up.

249 = 562949953421312

$ perl -E'say int( log(562949953421309) / log(2) )' 48 $ perl -E'say int( log(562949953421310) / log(2) )' 49 XXX $ perl -E'say int( log(562949953421311) / log(2) )' 49 XXX $ perl -E'say int( log(562949953421312) / log(2) )' 49 $ perl -E'say int( log(562949953421313) / log(2) )' 49

(Problem found by accident)


Comment on Re: May I be bitten by floating point arithmetic in the following restricted case?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://824912]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2014-09-02 07:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (20 votes), past polls