|
@@ -1,13 +1,85 @@
|
|
[[esql-pow]]
|
|
[[esql-pow]]
|
|
=== `POW`
|
|
=== `POW`
|
|
-Returns the the value of a base (first argument) raised to a power (second
|
|
|
|
-argument).
|
|
|
|
|
|
+Returns the value of a base (first argument) raised to the power of an exponent (second argument).
|
|
|
|
+Both arguments must be numeric.
|
|
|
|
|
|
[source.merge.styled,esql]
|
|
[source.merge.styled,esql]
|
|
----
|
|
----
|
|
-include::{esql-specs}/math.csv-spec[tag=pow]
|
|
|
|
|
|
+include::{esql-specs}/math.csv-spec[tag=powDI]
|
|
----
|
|
----
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
[%header.monospaced.styled,format=dsv,separator=|]
|
|
|===
|
|
|===
|
|
-include::{esql-specs}/math.csv-spec[tag=pow-result]
|
|
|
|
|
|
+include::{esql-specs}/math.csv-spec[tag=powDI-result]
|
|
|
|
+|===
|
|
|
|
+
|
|
|
|
+The type of the returned value is determined by the types of the base and exponent.
|
|
|
|
+The following rules are applied to determine the result type:
|
|
|
|
+
|
|
|
|
+* If either of the base or exponent are of a floating point type, the result will be a double
|
|
|
|
+* Otherwise, if either the base of the exponent are 64-bit (long or unsigned long), the result will be a long
|
|
|
|
+* Otherwise, the result will be a 32-bit integer (all other numeric types, including int, short and byte)
|
|
|
|
+
|
|
|
|
+For example, using simple integers as arguments will lead to an integer result:
|
|
|
|
+
|
|
|
|
+[source.merge.styled,esql]
|
|
|
|
+----
|
|
|
|
+include::{esql-specs}/math.csv-spec[tag=powII]
|
|
|
|
+----
|
|
|
|
+[%header.monospaced.styled,format=dsv,separator=|]
|
|
|
|
+|===
|
|
|
|
+include::{esql-specs}/math.csv-spec[tag=powII-result]
|
|
|
|
+|===
|
|
|
|
+
|
|
|
|
+Numeric overruns do not result in an error. For example:
|
|
|
|
+
|
|
|
|
+[source.merge.styled,esql]
|
|
|
|
+----
|
|
|
|
+include::{esql-specs}/math.csv-spec[tag=powULOverrun]
|
|
|
|
+----
|
|
|
|
+[%header.monospaced.styled,format=dsv,separator=|]
|
|
|
|
+|===
|
|
|
|
+include::{esql-specs}/math.csv-spec[tag=powULOverrun-result]
|
|
|
|
+|===
|
|
|
|
+
|
|
|
|
+If it is desired to protect against numeric overruns, use `to_double` on any one of the arguments:
|
|
|
|
+
|
|
|
|
+[source.merge.styled,esql]
|
|
|
|
+----
|
|
|
|
+include::{esql-specs}/math.csv-spec[tag=pow2d]
|
|
|
|
+----
|
|
|
|
+[%header.monospaced.styled,format=dsv,separator=|]
|
|
|
|
+|===
|
|
|
|
+include::{esql-specs}/math.csv-spec[tag=pow2d-result]
|
|
|
|
+|===
|
|
|
|
+
|
|
|
|
+For clarity, the following table describes the output result type for all combinations of numeric input types:
|
|
|
|
+
|
|
|
|
+[cols="1,1,1"]
|
|
|
|
+|===
|
|
|
|
+|Base | Exponent | Result
|
|
|
|
+
|
|
|
|
+|double/float/half_float
|
|
|
|
+|*footnote:all[All numeric types]
|
|
|
|
+|double
|
|
|
|
+
|
|
|
|
+|*footnote:all[]
|
|
|
|
+|double/float/half_float
|
|
|
|
+|double
|
|
|
|
+
|
|
|
|
+|long/unsigned long
|
|
|
|
+|*footnote:all_but_float[All except double/float/half_float]
|
|
|
|
+|long
|
|
|
|
+
|
|
|
|
+|*footnote:all_but_float[]
|
|
|
|
+|long/unsigned long
|
|
|
|
+|long
|
|
|
|
+
|
|
|
|
+|*footnote:all_but_float_and_64[All except floating point and 64-bit types]
|
|
|
|
+|*footnote:all_but_float_and_64[]
|
|
|
|
+|int
|
|
|
|
+
|
|
|
|
+|*footnote:all_but_float_and_64[]
|
|
|
|
+|*footnote:all_but_float_and_64[]
|
|
|
|
+|int
|
|
|
|
+
|
|
|===
|
|
|===
|