^ ( x y -- z )
Factor documentation > Factor handbook > The language > Numbers > Mathematical functions > Powers and logarithms
Prev:log10 ( x -- y )
Next:10^ ( x -- y )


Vocabulary
math.functions

Inputs and outputs
xa number
ya number
za 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
;

IN: math.functions

: ^ ( x y -- z )
{
{ [ over zero? ] [ 0^ ] }
{ [ dup integer? ] [ integer^ ] }
{ [ 2dup real^? ] [ [ >float ] bi@ fpow ] }
[ ^complex ]
} cond ; inline