Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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 imbibing at the Monastery: (5)
As of 2015-07-04 02:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls