Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://824912]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2017-07-22 09:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (337 votes). Check out past polls.