^ ( x y -- x^y ) (original) (raw)
^ ( x y -- x^y )
Factor handbook » The language » Numbers » Mathematical functions » Powers and logarithms
Prev: | logn ( x n -- y ) |
---|---|
Next: | e^ ( x -- e^x ) |
Inputs
x | a number |
---|---|
y | a number |
Outputs
x^y | a number |
---|
Word description
Raises x to the power of y. If y is an integer the answer is computed exactly, otherwise a floating point approximation is used.
Errors
Throws an error if x and y are both integer 0.
Definition
USING: combinators kernel math math.functions.private math.libm
;
: ^ ( x y -- x^y )
{
{ [ over zero? ] [ 0^ ] }
{ [ dup integer? ] [ ^integer ] }
{ [ 2dup real^? ] [ [ >float ] bi@ fpow ] }
[ ^complex ]
} cond ; inline