#### Wiki source for KeyPgOpExponentiate

Show raw source

{{fbdoc item="title" value="Operator ^ (Exponentiate)"}}----
Raises a numeric expression to some power

{{fbdoc item="syntax"}}##
[[KeyPgDeclare|declare]] [[KeyPgOperator|operator]] **^** ( [[KeyPgByref|byref]] //lhs// [[KeyPgAs|as]] [[KeyPgDouble|double]], [[KeyPgByref|byref]] //rhs// [[KeyPgAs|as]] [[KeyPgDouble|double]] ) [[KeyPgAs|as]] [[KeyPgDouble|double]]
##
{{fbdoc item="usage"}}##
//result// = //lhs// **^** //rhs//
##
{{fbdoc item="param"}}
##//lhs//##
The left-hand side base expression.
##//rhs//##
The right-hand side exponent expression.

{{fbdoc item="ret"}}
Returns the exponentiation of a base expression raised to some exponent.

{{fbdoc item="desc"}}
**##Operator ^## (Exponentiate)** returns the result of a base expression (##//lhs//##) raised to some exponent expression (##//rhs//##). ##**^**## works with double float numbers only, operands of other types will be converted into double before performing the exponentiation. Exponent of a fractional value (##1""/""//n//##) is the same as taking ##//n//##th root from the base, for example, ##2 **^** (1/3)## is the cube root of 2.

Neither of the operands are modified in any way.

Note: this operation is not guaranteed to be fully accurate, and there may be some inaccuracy in the least significant bits of the number. This is particularly noticeable when the result is expected to be an exact number: in these cases, you may find the result is out by a very small amount. For this reason, you should never assume that an exponentiation expression will be exactly equal to the value you expect.
This also means that you should be wary of using rounding methods such as ##[[KeyPgInt|Int]]## and ##[[KeyPgFix|Fix]]## on the result: if you expect the result to be an integer value, then there's a chance that it might be slightly lower, and will round down to a value that is one less than you would expect.

This operator can be overloaded for user-defined types.

Note: This operator exists in C/""C++"" with a different meaning - there it performs a Bitwise ##[[KeyPgOpXor|Xor]]##.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/operator/exponent.bas"}}%%(freebasic)
DIM AS DOUBLE n
INPUT "Please enter a positive number: ", n
PRINT
PRINT n;" squared is "; n ^ 2
PRINT "The fifth root of "; n;" is "; n ^ 0.2
SLEEP
%%
Output:
%%
Please enter a positive number: 3.4

3.4 squared is 11.56
The fifth root of 3.4 is 1.27730844458754
%%

{{fbdoc item="lang"}}
- In the //[[CompilerOptlang|-lang qb]]// dialect, this operator cannot be overloaded.

{{fbdoc item="diff"}}
- None

{{fbdoc item="see"}}
- [[CatPgMath|Mathematical Functions]]

{{fbdoc item="back" value="CatPgOpArithmetic|Arithmetic Operators"}}{{fbdoc item="back" value="CatPgOperators|Operators"}}