Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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 the monks are chillaxin'...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2017-11-18 09:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (277 votes). Check out past polls.

    Notices?