Mathematical Functions and Operators

Applies to: ✅ Data Cloud SQL ✅ Tableau Hyper API

This table contains the available mathematical operators.

OperatorDescriptionExample
+addition2 + 35
-subtraction2 - 3-1
*multiplication2 * 36
/division (integer division truncates the result)4 / 22
%modulo (remainder)5 % 41
^exponentiation (associates left to right)2.0 ^ 3.08
`square root25.0` 5
`cube root27.0`3
@absolute value@ -5.05
&bitwise AND91 & 1511
`bitwise OR3`35
#bitwise XOR17 # 520
~bitwise NOT~1-2
<<bitwise shift left1 << 416
>>bitwise shift right8 >> 22

The bitwise operators work only on integral data types, whereas the others are available for all numeric data types.

The next table shows the available mathematical functions. In the table, dp means double precision. Many of these functions are provided in multiple forms with different argument types. Except where noted, functions return the same data type as its argument return an error in case of failure.

FunctionReturn TypeDescriptionExample
abs(x)same as inputabsolute valueabs(-17.4)17.4
cbrt(dp)dpcube rootcbrt(27.0)3.0
ceil(dp or numeric)same as inputnearest integer greater than or equal to argumentceil(-42.8)-42.0
ceiling(dp or numeric)same as inputnearest integer greater than or equal to argument (same as ceil)ceiling(-95.3)-95.0
degrees(dp)dpradians to degreesdegrees(0.5)28.6478897565412
div(y, x)same as input, bigint for numericinteger quotient of y/xdiv(9,4)2
exp(x)dpexponentialexp(1.0)2.71828182845905
floor(dp or numeric)same as inputnearest integer less than or equal to argumentfloor(-42.8)-43.0
ln(x)dpnatural logarithmln(2.0)0.693147180559945
log(x)dpbase 10 logarithmlog(100.0)2.0
log(b, x)dplogarithm to base blog(2.0, 64.0)6.0000000000
mod(y, x)same as input, bigint for numericremainder of y/xmod(9,4)1
pi()dp"𝜋" constantpi()3.14159265358979
power(a, b)dp or numerica raised to the power of bpower(9.0, 3.0)729
radians(x)dpdegrees to radiansradians(45.0)0.785398163397448
random()dprandom value in the range 0.0 <= x < 1.0random()0.6817331
round(dp or numeric)same as inputround to nearest integerround(42.4)42
round(v dp or numeric, s int)same as inputround to s decimal placesround(42.4382, 2)42.44
sign(x)same as inputsign of the argument (-1, 0, +1)sign(-8.4)-1
sqrt(x)dpsquare rootsqrt(2.0)1.4142135623731
trunc(dp or numeric)same as inputtruncate toward zerotrunc(42.8)42
trunc(v dp or numeric, s int)same as inputtruncate to s decimal placestrunc(42.4382, 2)42.43
width_bucket(operand, b1, b2, count int)intreturn the bucket number to which operand would be assigned in a histogram having count equal-width buckets spanning the range b1 to b2; returns 0 or count+1 for an input outside the rangewidth_bucket(5.35, 0.024, 10.06, 5)3

The characteristics of the values returned by random() depend on the system implementation. It’s not suitable for cryptographic applications.

Trigonometric functions are also available.

Function (radians)Description
acos(x)inverse cosine
asin(x)inverse sine
atan(x)inverse tangent
atan2(y, x)inverse tangent of y/x
cos(x)cosine
cot(x)cotangent
sin(x)sine
tan(x)tangent

All trigonometric functions return values of type double precision.