Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Power of two round up.

by Dominus (Parson)
on Dec 16, 2000 at 22:24 UTC ( #47061=note: print w/ replies, xml ) Need Help??


in reply to Re: Power of two round up.
in thread Power of two round up.

I'm amazed at how clever this is, and I'm going to use it in my program. Thanks a lot.


Comment on Re: Power of two round up.
Re: Re: Power of two round up.
by I0 (Priest) on Dec 17, 2000 at 05:29 UTC
    Although it's a technique more appropriate in a C program. In Perl, log($_)/log(2) benchmarks faster. (assuming it rounds properly at the boundaries)
    Update: My earlier timethese qq{} may have been misleading. With timethese sub{} the | >> method comes out faster
      Sure, because it has to dispatch many fewer opcodes. But if I had wanted to use the log2 x solution, I wouldn't have asked in the first place. Floating-point arithmetic gives me the heebie-jeebies.

        Floating-point gives me heebie-jeebies too. (in fact, a floating conversion seems to be what makes the |>> method fail for @_ = (0)
        --then again, log(0) doesn't work either, and the |>> method does work for @_=(0) if you use integer;)
        P.S. Why does an opcode fetch take longer than a transcendental function? I'm sure that part of the interpreter must have been fully optimized.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2015-07-04 21:04 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 (60 votes), past polls