Game Maker Games, Articles, Tutorials & More

Game Maker Network


Howdy, Guest! Please sign in or register an account.

Print

is_power

By Daniel · December 26, 2008

Tests whether n is a power of base; more precisely, whether there exists some power p such that base^p = n.

/* is_power(n, base)
 *
 * Tests whether n is a power of base; more precisely, whether there exists
 * some power p such that base^p = n.
 */

if (argument0 == 0) return (argument1 == 0);
if (argument1 == 0) return (argument0 == 1) * -1;
if (argument1 == 1) return (argument0 == 1);
return ((logn(argument1, argument0) mod 1) == 0);

Categories: Mathematics

Comments

There are no comments to display.

Post a Comment

You must be signed in to post comments.

Advertisement