Next two Square of x

I had a quick need for a function that returns the next square pf 2 nearest to the given number…Here is the one line code to do just that…Is there something better?

Gist of the Function on Github

function nextPow2(x) {
return Math.pow(2, Math.round(Math.max(x,0)).toString(2).length);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s