Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^8: a close prime number

by Limbic~Region (Chancellor)
on Feb 14, 2005 at 17:00 UTC ( #430854=note: print w/ replies, xml ) Need Help??

in reply to Re^7: a close prime number
in thread a close prime number

I understand the point you were trying to make, but you picked a bad example.

print nearest_power_of_2( 50 ); sub nearest_power_of_2 { my $x = shift; my $n = log( $x ) / log( 2 ); return $x if $n == int $n; my ($below, $above) = (int $n, int $n + 1); $_ = 2 ** $_ for ($above, $below); return $above - $x > $x - $below ? $below : $above; }

Cheers - L~R

Thanks to blokhead for reminding me how to convert logarithmic bases

Comment on Re^8: a close prime number
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2015-12-01 07:45 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (795 votes), past polls