Mathematical functions

GoogleSQL for Bigtable supports mathematical functions. All mathematical functions have the following behaviors:

  • They return NULL if any of the input parameters is NULL.
  • They return NaN if any of the arguments is NaN.

Categories

CategoryFunctions
TrigonometricACOS   ACOSH   ASIN   ASINH   ATAN   ATAN2   ATANH   COS   COSH   COT   COTH   CSC   CSCH   SEC   SECH   SIN   SINH   TAN   TANH  
Exponential and
logarithmic
EXP   LN   LOG   LOG10  
Rounding and
truncation
CEIL   CEILING   FLOOR   ROUND   TRUNC  
Power and
root
POW   POWER   SQRT  
SignABS   SIGN  
DistanceCOSINE_DISTANCE   EUCLIDEAN_DISTANCE  
ComparisonGREATEST   LEAST  
Random number generatorRAND  
Arithmetic and error handlingDIV   IEEE_DIVIDE   IS_INF   IS_NAN   MOD   SAFE_ADD   SAFE_DIVIDE   SAFE_MULTIPLY   SAFE_NEGATE   SAFE_SUBTRACT  

Function list

NameSummary
ABSComputes the absolute value of X.
ACOSComputes the inverse cosine of X.
ACOSHComputes the inverse hyperbolic cosine of X.
ASINComputes the inverse sine of X.
ASINHComputes the inverse hyperbolic sine of X.
ATANComputes the inverse tangent of X.
ATAN2Computes the inverse tangent of X/Y, using the signs of X and Y to determine the quadrant.
ATANHComputes the inverse hyperbolic tangent of X.
CEILGets the smallest integral value that isn't less than X.
CEILINGSynonym of CEIL.
COSComputes the cosine of X.
COSHComputes the hyperbolic cosine of X.
COSINE_DISTANCEComputes the cosine distance between two vectors.
COTComputes the cotangent of X.
COTHComputes the hyperbolic cotangent of X.
CSCComputes the cosecant of X.
CSCHComputes the hyperbolic cosecant of X.
DIVDivides integer X by integer Y.
EXPComputes e to the power of X.
EUCLIDEAN_DISTANCEComputes the Euclidean distance between two vectors.
FLOORGets the largest integral value that isn't greater than X.
GREATESTGets the greatest value among X1,...,XN.
IEEE_DIVIDEDivides X by Y, but doesn't generate errors for division by zero or overflow.
IS_INFChecks if X is positive or negative infinity.
IS_NANChecks if X is a NaN value.
LEASTGets the least value among X1,...,XN.
LNComputes the natural logarithm of X.
LOGComputes the natural logarithm of X or the logarithm of X to base Y.
LOG10Computes the natural logarithm of X to base 10.
MODGets the remainder of the division of X by Y.
POWProduces the value of X raised to the power of Y.
POWERSynonym of POW.
RANDGenerates a pseudo-random value of type FLOAT64 in the range of [0, 1).
ROUNDRounds X to the nearest integer or rounds X to N decimal places after the decimal point.
SAFE_ADDEquivalent to the addition operator (X + Y), but returns NULL if overflow occurs.
SAFE_DIVIDEEquivalent to the division operator (X / Y), but returns NULL if an error occurs.
SAFE_MULTIPLYEquivalent to the multiplication operator (X * Y), but returns NULL if overflow occurs.
SAFE_NEGATEEquivalent to the unary minus operator (-X), but returns NULL if overflow occurs.
SAFE_SUBTRACTEquivalent to the subtraction operator (X - Y), but returns NULL if overflow occurs.
SECComputes the secant of X.
SECHComputes the hyperbolic secant of X.
SIGNProduces -1 , 0, or +1 for negative, zero, and positive arguments respectively.
SINComputes the sine of X.
SINHComputes the hyperbolic sine of X.
SQRTComputes the square root of X.
TANComputes the tangent of X.
TANHComputes the hyperbolic tangent of X.
TRUNCRounds a number like ROUND(X) or ROUND(X, N), but always rounds towards zero and never overflows.

ABS

ABS(X)

Description

Computes absolute value. Returns an error if the argument is an integer and the output value can't be represented as the same type; this happens only for the largest negative input value, which has no positive representation.

XABS(X)
2525
-2525
+inf+inf
-inf+inf

Return Data Type

INPUTINT64FLOAT32FLOAT64
OUTPUTINT64FLOAT32FLOAT64

ACOS

ACOS(X)

Description

Computes the principal value of the inverse cosine of X. The return value is in the range [0,π]. Generates an error if X is a value outside of the range [-1, 1].

XACOS(X)
+infNaN
-infNaN
NaNNaN
X < -1Error
X > 1Error

ACOSH

ACOSH(X)

Description

Computes the inverse hyperbolic cosine of X. Generates an error if X is a value less than 1.

XACOSH(X)
+inf+inf
-infNaN
NaNNaN
X < 1Error

ASIN

ASIN(X)

Description

Computes the principal value of the inverse sine of X. The return value is in the range [-π/2,π/2]. Generates an error if X is outside of the range [-1, 1].

XASIN(X)
+infNaN
-infNaN
NaNNaN
X < -1Error
X > 1Error

ASINH

ASINH(X)

Description

Computes the inverse hyperbolic sine of X. Doesn't fail.

XASINH(X)
+inf+inf
-inf-inf
NaNNaN

ATAN

ATAN(X)

Description

Computes the principal value of the inverse tangent of X. The return value is in the range [-π/2,π/2]. Doesn't fail.

XATAN(X)
+infπ/2
-inf-π/2
NaNNaN

ATAN2

ATAN2(X, Y)

Description

Calculates the principal value of the inverse tangent of X/Y using the signs of the two arguments to determine the quadrant. The return value is in the range [-π,π].

XYATAN2(X, Y)
NaNAny valueNaN
Any valueNaNNaN
0.00.00.0
Positive Finite value-infπ
Negative Finite value-inf
Finite value+inf0.0
+infFinite valueπ/2
-infFinite value-π/2
+inf-inf¾π
-inf-inf-¾π
+inf+infπ/4
-inf+inf-π/4

ATANH

ATANH(X)

Description

Computes the inverse hyperbolic tangent of X. Generates an error if X is outside of the range (-1, 1).

XATANH(X)
+infNaN
-infNaN
NaNNaN
X < -1Error
X > 1Error

CEIL

CEIL(X)

Description

Returns the smallest integral value that isn't less than X.

XCEIL(X)
2.02.0
2.33.0
2.83.0
2.53.0
-2.3-2.0
-2.8-2.0
-2.5-2.0
00
+inf+inf
-inf-inf
NaNNaN

Return Data Type

INPUTINT64FLOAT32FLOAT64
OUTPUTFLOAT64FLOAT64FLOAT64

CEILING

CEILING(X)

Description

Synonym of CEIL(X)

COS

COS(X)

Description

Computes the cosine of X where X is specified in radians. Never fails.

XCOS(X)
+infNaN
-infNaN
NaNNaN

COSH

COSH(X)

Description

Computes the hyperbolic cosine of X where X is specified in radians. Generates an error if overflow occurs.

XCOSH(X)
+inf+inf
-inf+inf
NaNNaN

COSINE_DISTANCE

COSINE_DISTANCE(vector1, vector2)

Description

Computes the cosine distance between two vectors.

Definitions

  • vector1: A vector that's represented by an ARRAY<T> value or a sparse vector that is represented by an ARRAY<STRUCT<dimension,magnitude>> value.
  • vector2: A vector that's represented by an ARRAY<T> value or a sparse vector that is represented by an ARRAY<STRUCT<dimension,magnitude>> value.

Details

  • ARRAY<T> can be used to represent a vector. Each zero-based index in this array represents a dimension. The value for each element in this array represents a magnitude.

    T can represent the following and must be the same for both vectors:

    • FLOAT32
    • FLOAT64

    In the following example vector, there are four dimensions. The magnitude is 10.0 for dimension 0, 55.0 for dimension 1, 40.0 for dimension 2, and 34.0 for dimension 3:

    [10.0, 55.0, 40.0, 34.0]
    
  • ARRAY<STRUCT<dimension,magnitude>> can be used to represent a sparse vector. With a sparse vector, you only need to include dimension-magnitude pairs for non-zero magnitudes. If a magnitude isn't present in the sparse vector, the magnitude is implicitly understood to be zero.

    For example, if you have a vector with 10,000 dimensions, but only 10 dimensions have non-zero magnitudes, then the vector is a sparse vector. As a result, it's more efficient to describe a sparse vector by only mentioning its non-zero magnitudes.

    In ARRAY<STRUCT<dimension,magnitude>>, STRUCT<dimension,magnitude> represents a dimension-magnitude pair for each non-zero magnitude in a sparse vector. These parts need to be included for each dimension-magnitude pair:

    • dimension: A STRING or INT64 value that represents a dimension in a vector.

    • magnitude: A FLOAT64 value that represents a non-zero magnitude for a specific dimension in a vector.

    You don't need to include empty dimension-magnitude pairs in a sparse vector. For example, the following sparse vector and non-sparse vector are equivalent:

    -- sparse vector ARRAY<STRUCT<INT64, FLOAT64>>
    [(1, 10.0), (2, 30.0), (5, 40.0)]
    
    -- vector ARRAY<FLOAT64>
    [0.0, 10.0, 30.0, 0.0, 0.0, 40.0]
    

    In a sparse vector, dimension-magnitude pairs don't need to be in any particular order. The following sparse vectors are equivalent:

    [('a', 10.0), ('b', 30.0), ('d', 40.0)]
    
    [('d', 40.0), ('a', 10.0), ('b', 30.0)]
    
  • Both non-sparse vectors in this function must share the same dimensions, and if they don't, an error is produced.

  • A vector can't be a zero vector. A vector is a zero vector if it has no dimensions or all dimensions have a magnitude of 0, such as [] or [0.0, 0.0]. If a zero vector is encountered, an error is produced.

  • An error is produced if a magnitude in a vector is NULL.

  • If a vector is NULL, NULL is returned.

Return type

FLOAT64

Examples

In the following example, non-sparsevectors are used to compute the cosine distance:

SELECT COSINE_DISTANCE([1.0, 2.0], [3.0, 4.0]) AS results;

/*----------*
 | results  |
 +----------+
 | 0.016130 |
 *----------*/

In the following example, sparse vectors are used to compute the cosine distance:

SELECT COSINE_DISTANCE(
 [(1, 1.0), (2, 2.0)],
 [(2, 4.0), (1, 3.0)]) AS results;

 /*----------*
  | results  |
  +----------+
  | 0.016130 |
  *----------*/

The ordering of numeric values in a vector doesn't impact the results produced by this function. For example these queries produce the same results even though the numeric values in each vector is in a different order:

SELECT COSINE_DISTANCE([1.0, 2.0], [3.0, 4.0]) AS results;
SELECT COSINE_DISTANCE([2.0, 1.0], [4.0, 3.0]) AS results;
SELECT COSINE_DISTANCE([(1, 1.0), (2, 2.0)], [(1, 3.0), (2, 4.0)]) AS results;
 /*----------*
  | results  |
  +----------+
  | 0.016130 |
  *----------*/

In the following example, the function can't compute cosine distance against the first vector, which is a zero vector:

-- ERROR
SELECT COSINE_DISTANCE([0.0, 0.0], [3.0, 4.0]) AS results;
-- ERROR
SELECT COSINE_DISTANCE([(1, 0.0), (2, 0.0)], [(1, 3.0), (2, 4.0)]) AS results;

Both non-sparse vectors must have the same dimensions. If not, an error is produced. In the following example, the first vector has two dimensions and the second vector has three:

-- ERROR
SELECT COSINE_DISTANCE([9.0, 7.0], [8.0, 4.0, 5.0]) AS results;

If you use sparse vectors and you repeat a dimension, an error is produced:

-- ERROR
SELECT COSINE_DISTANCE(
  [(1, 9.0), (2, 7.0), (2, 8.0)], [(1, 8.0), (2, 4.0), (3, 5.0)]) AS results;

COT

COT(X)

Description

Computes the cotangent for the angle of X, where X is specified in radians. X can be any data type that coerces to FLOAT64. Supports the SAFE. prefix.

XCOT(X)
+infNaN
-infNaN
NaNNaN
0Error
NULLNULL

Return Data Type

FLOAT64

Example

SELECT COT(1) AS a, SAFE.COT(0) AS b;

/*---------------------+------*
 | a                   | b    |
 +---------------------+------+
 | 0.64209261593433065 | NULL |
 *---------------------+------*/

COTH

COTH(X)

Description

Computes the hyperbolic cotangent for the angle of X, where X is specified in radians. X can be any data type that coerces to FLOAT64. Supports the SAFE. prefix.

XCOTH(X)
+inf1
-inf-1
NaNNaN
0Error
NULLNULL

Return Data Type

FLOAT64

Example

SELECT COTH(1) AS a, SAFE.COTH(0) AS b;

/*----------------+------*
 | a              | b    |
 +----------------+------+
 | 1.313035285499 | NULL |
 *----------------+------*/

CSC

CSC(X)

Description

Computes the cosecant of the input angle, which is in radians. X can be any data type that coerces to FLOAT64. Supports the SAFE. prefix.

XCSC(X)
+infNaN
-infNaN
NaNNaN
0Error
NULLNULL

Return Data Type

FLOAT64

Example

SELECT CSC(100) AS a, CSC(-1) AS b, SAFE.CSC(0) AS c;

/*----------------+-----------------+------*
 | a              | b               | c    |
 +----------------+-----------------+------+
 | -1.97485753142 | -1.188395105778 | NULL |
 *----------------+-----------------+------*/

CSCH

CSCH(X)

Description

Computes the hyperbolic cosecant of the input angle, which is in radians. X can be any data type that coerces to FLOAT64. Supports the SAFE. prefix.

XCSCH(X)
+inf0
-inf0
NaNNaN
0Error
NULLNULL

Return Data Type

FLOAT64

Example

SELECT CSCH(0.5) AS a, CSCH(-2) AS b, SAFE.CSCH(0) AS c;

/*----------------+----------------+------*
 | a              | b              | c    |
 +----------------+----------------+------+
 | 1.919034751334 | -0.27572056477 | NULL |
 *----------------+----------------+------*/

DIV

DIV(X, Y)

Description

Returns the result of integer division of X by Y. Division by zero returns an error. Division by -1 may overflow.

XYDIV(X, Y)
2045
12-7-1
2036
0200
200Error

Return Data Type

The return data type is determined by the argument types with the following table.

INPUTINT64
INT64INT64

EXP

EXP(X)

Description

Computes e to the power of X, also called the natural exponential function. If the result underflows, this function returns a zero. Generates an error if the result overflows.

XEXP(X)
0.01.0
+inf+inf
-inf0.0

Return Data Type

INPUTINT64FLOAT32FLOAT64
OUTPUTFLOAT64FLOAT64FLOAT64

EUCLIDEAN_DISTANCE

EUCLIDEAN_DISTANCE(vector1, vector2)

Description

Computes the Euclidean distance between two vectors.

Definitions

  • vector1: A vector that's represented by an ARRAY<T> value or a sparse vector that is represented by an ARRAY<STRUCT<dimension,magnitude>> value.
  • vector2: A vector that's represented by an ARRAY<T> value or a sparse vector that is represented by an ARRAY<STRUCT<dimension,magnitude>> value.

Details

  • ARRAY<T> can be used to represent a vector. Each zero-based index in this array represents a dimension. The value for each element in this array represents a magnitude.

    T can represent the following and must be the same for both vectors:

    • FLOAT32
    • FLOAT64

    In the following example vector, there are four dimensions. The magnitude is 10.0 for dimension 0, 55.0 for dimension 1, 40.0 for dimension 2, and 34.0 for dimension 3:

    [10.0, 55.0, 40.0, 34.0]
    
  • ARRAY<STRUCT<dimension,magnitude>> can be used to represent a sparse vector. With a sparse vector, you only need to include dimension-magnitude pairs for non-zero magnitudes. If a magnitude isn't present in the sparse vector, the magnitude is implicitly understood to be zero.

    For example, if you have a vector with 10,000 dimensions, but only 10 dimensions have non-zero magnitudes, then the vector is a sparse vector. As a result, it's more efficient to describe a sparse vector by only mentioning its non-zero magnitudes.

    In ARRAY<STRUCT<dimension,magnitude>>, STRUCT<dimension,magnitude> represents a dimension-magnitude pair for each non-zero magnitude in a sparse vector. These parts need to be included for each dimension-magnitude pair:

    • dimension: A STRING or INT64 value that represents a dimension in a vector.

    • magnitude: A FLOAT64 value that represents a non-zero magnitude for a specific dimension in a vector.

    You don't need to include empty dimension-magnitude pairs in a sparse vector. For example, the following sparse vector and non-sparse vector are equivalent:

    -- sparse vector ARRAY<STRUCT<INT64, FLOAT64>>
    [(1, 10.0), (2, 30.0), (5, 40.0)]
    
    -- vector ARRAY<FLOAT64>
    [0.0, 10.0, 30.0, 0.0, 0.0, 40.0]
    

    In a sparse vector, dimension-magnitude pairs don't need to be in any particular order. The following sparse vectors are equivalent:

    [('a', 10.0), ('b', 30.0), ('d', 40.0)]
    
    [('d', 40.0), ('a', 10.0), ('b', 30.0)]
    
  • Both non-sparse vectors in this function must share the same dimensions, and if they don't, an error is produced.

  • A vector can be a zero vector. A vector is a zero vector if it has no dimensions or all dimensions have a magnitude of 0, such as [] or [0.0, 0.0].

  • An error is produced if a magnitude in a vector is NULL.

  • If a vector is NULL, NULL is returned.

Return type

FLOAT64

Examples

In the following example, non-sparse vectors are used to compute the Euclidean distance:

SELECT EUCLIDEAN_DISTANCE([1.0, 2.0], [3.0, 4.0]) AS results;

/*----------*
 | results  |
 +----------+
 | 2.828    |
 *----------*/

In the following example, sparse vectors are used to compute the Euclidean distance:

SELECT EUCLIDEAN_DISTANCE(
 [(1, 1.0), (2, 2.0)],
 [(2, 4.0), (1, 3.0)]) AS results;

 /*----------*
  | results  |
  +----------+
  | 2.828    |
  *----------*/

The ordering of magnitudes in a vector doesn't impact the results produced by this function. For example these queries produce the same results even though the magnitudes in each vector is in a different order:

SELECT EUCLIDEAN_DISTANCE([1.0, 2.0], [3.0, 4.0]);
SELECT EUCLIDEAN_DISTANCE([2.0, 1.0], [4.0, 3.0]);
SELECT EUCLIDEAN_DISTANCE([(1, 1.0), (2, 2.0)], [(1, 3.0), (2, 4.0)]) AS results;
 /*----------*
  | results  |
  +----------+
  | 2.828    |
  *----------*/

Both non-sparse vectors must have the same dimensions. If not, an error is produced. In the following example, the first vector has two dimensions and the second vector has three:

-- ERROR
SELECT EUCLIDEAN_DISTANCE([9.0, 7.0], [8.0, 4.0, 5.0]) AS results;

If you use sparse vectors and you repeat a dimension, an error is produced:

-- ERROR
SELECT EUCLIDEAN_DISTANCE(
  [(1, 9.0), (2, 7.0), (2, 8.0)], [(1, 8.0), (2, 4.0), (3, 5.0)]) AS results;

FLOOR

FLOOR(X)

Description

Returns the largest integral value that isn't greater than X.

XFLOOR(X)
2.02.0
2.32.0
2.82.0
2.52.0
-2.3-3.0
-2.8-3.0
-2.5-3.0
00
+inf+inf
-inf-inf
NaNNaN

Return Data Type

INPUTINT64FLOAT32FLOAT64
OUTPUTFLOAT64FLOAT64FLOAT64

GREATEST

GREATEST(X1,...,XN)

Description

Returns the greatest value among X1,...,XN. If any argument is NULL, returns NULL. Otherwise, in the case of floating-point arguments, if any argument is NaN, returns NaN. In all other cases, returns the value among X1,...,XN that has the greatest value according to the ordering used by the ORDER BY clause. The arguments X1, ..., XN must be coercible to a common supertype, and the supertype must support ordering.

X1,...,XNGREATEST(X1,...,XN)
3,5,15

This function supports specifying collation.

Return Data Types

Data type of the input values.

IEEE_DIVIDE

IEEE_DIVIDE(X, Y)

Description

Divides X by Y; this function never fails. Returns FLOAT64 unless both X and Y are FLOAT32, in which case it returns FLOAT32. Unlike the division operator (/), this function doesn't generate errors for division by zero or overflow.

XYIEEE_DIVIDE(X, Y)
20.04.05.0
0.025.00.0
25.00.0+inf
-25.00.0-inf
0.00.0NaN
0.0NaNNaN
NaN0.0NaN
+inf+infNaN
-inf-infNaN

IS_INF

IS_INF(X)

Description

Returns TRUE if the value is positive or negative infinity.

XIS_INF(X)
+infTRUE
-infTRUE
25FALSE

IS_NAN

IS_NAN(X)

Description

Returns TRUE if the value is a NaN value.

XIS_NAN(X)
NaNTRUE
25FALSE

LEAST

LEAST(X1,...,XN)

Description

Returns the least value among X1,...,XN. If any argument is NULL, returns NULL. Otherwise, in the case of floating-point arguments, if any argument is NaN, returns NaN. In all other cases, returns the value among X1,...,XN that has the least value according to the ordering used by the ORDER BY clause. The arguments X1, ..., XN must be coercible to a common supertype, and the supertype must support ordering.

X1,...,XNLEAST(X1,...,XN)
3,5,11

This function supports specifying collation.

Return Data Types

Data type of the input values.

LN

LN(X)

Description

Computes the natural logarithm of X. Generates an error if X is less than or equal to zero.

XLN(X)
1.00.0
+inf+inf
X <= 0Error

Return Data Type

INPUTINT64FLOAT32FLOAT64
OUTPUTFLOAT64FLOAT64FLOAT64

LOG

LOG(X [, Y])

Description

If only X is present, LOG is a synonym of LN. If Y is also present, LOG computes the logarithm of X to base Y.

XYLOG(X, Y)
100.010.02.0
-infAny valueNaN
Any value+infNaN
+inf0.0 < Y < 1.0-inf
+infY > 1.0+inf
X <= 0Any valueError
Any valueY <= 0Error
Any value1.0Error

Return Data Type

INPUTINT64FLOAT32FLOAT64
INT64FLOAT64FLOAT64FLOAT64
FLOAT32FLOAT64FLOAT64FLOAT64
FLOAT64FLOAT64FLOAT64FLOAT64

LOG10

LOG10(X)

Description

Similar to LOG, but computes logarithm to base 10.

XLOG10(X)
100.02.0
-infNaN
+inf+inf
X <= 0Error

Return Data Type

INPUTINT64FLOAT32FLOAT64
OUTPUTFLOAT64FLOAT64FLOAT64

MOD

MOD(X, Y)

Description

Modulo function: returns the remainder of the division of X by Y. Returned value has the same sign as X. An error is generated if Y is 0.

XYMOD(X, Y)
25121
250Error

Return Data Type

The return data type is determined by the argument types with the following table.

INPUTINT64
INT64INT64

POW

POW(X, Y)

Description

Returns the value of X raised to the power of Y. If the result underflows and isn't representable, then the function returns a value of zero.

XYPOW(X, Y)
2.03.08.0
1.0Any value including NaN1.0
Any value including NaN01.0
-1.0+inf1.0
-1.0-inf1.0
ABS(X) < 1-inf+inf
ABS(X) > 1-inf0.0
ABS(X) < 1+inf0.0
ABS(X) > 1+inf+inf
-infY < 00.0
-infY > 0-inf if Y is an odd integer, +inf otherwise
+infY < 00
+infY > 0+inf
Finite value < 0Non-integerError
0Finite value < 0Error

Return Data Type

The return data type is determined by the argument types with the following table.

INPUTINT64FLOAT32FLOAT64
INT64FLOAT64FLOAT64FLOAT64
FLOAT32FLOAT64FLOAT64FLOAT64
FLOAT64FLOAT64FLOAT64FLOAT64

POWER

POWER(X, Y)

Description

Synonym of POW(X, Y).

RAND

RAND()

Description

Generates a pseudo-random value of type FLOAT64 in the range of [0, 1), inclusive of 0 and exclusive of 1.

ROUND

ROUND(X [, N [, rounding_mode]])

Description

If only X is present, rounds X to the nearest integer. If N is present, rounds X to N decimal places after the decimal point. If N is negative, rounds off digits to the left of the decimal point. Rounds halfway cases away from zero. Generates an error if overflow occurs.

If X is a NUMERIC or BIGNUMERIC type, then you can explicitly set rounding_mode to one of the following:

If you set the rounding_mode and X isn't a NUMERIC or BIGNUMERIC type, then the function generates an error.

ExpressionReturn Value
ROUND(2.0)2.0
ROUND(2.3)2.0
ROUND(2.8)3.0
ROUND(2.5)3.0
ROUND(-2.3)-2.0
ROUND(-2.8)-3.0
ROUND(-2.5)-3.0
ROUND(0)0
ROUND(+inf)+inf
ROUND(-inf)-inf
ROUND(NaN)NaN
ROUND(123.7, -1)120.0
ROUND(1.235, 2)1.24
ROUND(NUMERIC "2.25", 1, "ROUND_HALF_EVEN")2.2
ROUND(NUMERIC "2.35", 1, "ROUND_HALF_EVEN")2.4
ROUND(NUMERIC "2.251", 1, "ROUND_HALF_EVEN")2.3
ROUND(NUMERIC "-2.5", 0, "ROUND_HALF_EVEN")-2
ROUND(NUMERIC "2.5", 0, "ROUND_HALF_AWAY_FROM_ZERO")3
ROUND(NUMERIC "-2.5", 0, "ROUND_HALF_AWAY_FROM_ZERO")-3

Return Data Type

INPUTINT64FLOAT32FLOAT64
OUTPUTFLOAT64FLOAT64FLOAT64

SAFE_ADD

SAFE_ADD(X, Y)

Description

Equivalent to the addition operator (+), but returns NULL if overflow occurs.

XYSAFE_ADD(X, Y)
549

Return Data Type

INPUTINT64FLOAT32FLOAT64
INT64INT64FLOAT64FLOAT64
FLOAT32FLOAT64FLOAT64FLOAT64
FLOAT64FLOAT64FLOAT64FLOAT64

SAFE_DIVIDE

SAFE_DIVIDE(X, Y)

Description

Equivalent to the division operator (X / Y), but returns NULL if an error occurs, such as a division by zero error.

XYSAFE_DIVIDE(X, Y)
2045
0200
200NULL

Return Data Type

INPUTINT64FLOAT32FLOAT64
INT64FLOAT64FLOAT64FLOAT64
FLOAT32FLOAT64FLOAT64FLOAT64
FLOAT64FLOAT64FLOAT64FLOAT64

SAFE_MULTIPLY

SAFE_MULTIPLY(X, Y)

Description

Equivalent to the multiplication operator (*), but returns NULL if overflow occurs.

XYSAFE_MULTIPLY(X, Y)
20480

Return Data Type

INPUTINT64FLOAT32FLOAT64
INT64INT64FLOAT64FLOAT64
FLOAT32FLOAT64FLOAT64FLOAT64
FLOAT64FLOAT64FLOAT64FLOAT64

SAFE_NEGATE

SAFE_NEGATE(X)

Description

Equivalent to the unary minus operator (-), but returns NULL if overflow occurs.

XSAFE_NEGATE(X)
+1-1
-1+1
00

Return Data Type

INPUTINT64FLOAT32FLOAT64
OUTPUTINT64FLOAT32FLOAT64

SAFE_SUBTRACT

SAFE_SUBTRACT(X, Y)

Description

Returns the result of Y subtracted from X. Equivalent to the subtraction operator (-), but returns NULL if overflow occurs.

XYSAFE_SUBTRACT(X, Y)
541

Return Data Type

INPUTINT64FLOAT32FLOAT64
INT64INT64FLOAT64FLOAT64
FLOAT32FLOAT64FLOAT64FLOAT64
FLOAT64FLOAT64FLOAT64FLOAT64

SEC

SEC(X)

Description

Computes the secant for the angle of X, where X is specified in radians. X can be any data type that coerces to FLOAT64.

XSEC(X)
+infNaN
-infNaN
NaNNaN
NULLNULL

Return Data Type

FLOAT64

Example

SELECT SEC(100) AS a, SEC(-1) AS b;

/*----------------+---------------*
 | a              | b             |
 +----------------+---------------+
 | 1.159663822905 | 1.85081571768 |
 *----------------+---------------*/

SECH

SECH(X)

Description

Computes the hyperbolic secant for the angle of X, where X is specified in radians. X can be any data type that coerces to FLOAT64. Never produces an error.

XSECH(X)
+inf0
-inf0
NaNNaN
NULLNULL

Return Data Type

FLOAT64

Example

SELECT SECH(0.5) AS a, SECH(-2) AS b, SECH(100) AS c;

/*----------------+----------------+---------------------*
 | a              | b              | c                   |
 +----------------+----------------+---------------------+
 | 0.88681888397  | 0.265802228834 | 7.4401519520417E-44 |
 *----------------+----------------+---------------------*/

SIGN

SIGN(X)

Description

Returns -1, 0, or +1 for negative, zero and positive arguments respectively. For floating point arguments, this function doesn't distinguish between positive and negative zero.

XSIGN(X)
25+1
00
-25-1
NaNNaN

Return Data Type

INPUTINT64FLOAT32FLOAT64
OUTPUTINT64FLOAT32FLOAT64

SIN

SIN(X)

Description

Computes the sine of X where X is specified in radians. Never fails.

XSIN(X)
+infNaN
-infNaN
NaNNaN

SINH

SINH(X)

Description

Computes the hyperbolic sine of X where X is specified in radians. Generates an error if overflow occurs.

XSINH(X)
+inf+inf
-inf-inf
NaNNaN

SQRT

SQRT(X)

Description

Computes the square root of X. Generates an error if X is less than 0.

XSQRT(X)
25.05.0
+inf+inf
X < 0Error

Return Data Type

INPUTINT64FLOAT32FLOAT64
OUTPUTFLOAT64FLOAT64FLOAT64

TAN

TAN(X)

Description

Computes the tangent of X where X is specified in radians. Generates an error if overflow occurs.

XTAN(X)
+infNaN
-infNaN
NaNNaN

TANH

TANH(X)

Description

Computes the hyperbolic tangent of X where X is specified in radians. Doesn't fail.

XTANH(X)
+inf1.0
-inf-1.0
NaNNaN

TRUNC

TRUNC(X [, N])

Description

If only X is present, TRUNC rounds X to the nearest integer whose absolute value isn't greater than the absolute value of X. If N is also present, TRUNC behaves like ROUND(X, N), but always rounds towards zero and never overflows.

XTRUNC(X)
2.02.0
2.32.0
2.82.0
2.52.0
-2.3-2.0
-2.8-2.0
-2.5-2.0
00
+inf+inf
-inf-inf
NaNNaN

Return Data Type

INPUTINT64FLOAT32FLOAT64
OUTPUTFLOAT64FLOAT64FLOAT64