Mathematical Functions

All math and trigonometric functions require their input (where applicable) to be numeric.

Generic

ABS

Synopsis:

  1. ABS(numeric_exp)

Input:

numeric expression

Output: numeric

Description: Returns the absolute value of numeric_exp. The return type is the same as the input type.

  1. SELECT ABS(-123.5), ABS(55);
  2. ABS(-123.5) | ABS(55)
  3. ---------------+---------------
  4. 123.5 |55

CBRT

Synopsis:

  1. CBRT(numeric_exp)

Input:

numeric expression

Output: double numeric value

Description: Returns the cube root of numeric_exp.

  1. SELECT CBRT(-125.5);
  2. CBRT(-125.5)
  3. -------------------
  4. -5.0066577974783435

CEIL/CEILING

Synopsis:

  1. CEIL(numeric_exp)

Input:

numeric expression

Output: integer or long numeric value

Description: Returns the smallest integer greater than or equal to numeric_exp.

  1. SELECT CEIL(125.01), CEILING(-125.99);
  2. CEIL(125.01) |CEILING(-125.99)
  3. ---------------+----------------
  4. 126 |-125

E

Synopsis:

  1. E()

Input: none

Output: 2.718281828459045

Description: Returns Euler’s number.

  1. SELECT E(), CEIL(E());
  2. E() | CEIL(E())
  3. -----------------+---------------
  4. 2.718281828459045|3

EXP

Synopsis:

  1. EXP(numeric_exp)

Input:

float numeric expression

Output: double numeric value

Description: Returns Euler’s number at the power of numeric_exp enumeric_exp.

  1. SELECT EXP(1), E(), EXP(2), E() * E();
  2. EXP(1) | E() | EXP(2) | E() * E()
  3. -----------------+-----------------+----------------+------------------
  4. 2.718281828459045|2.718281828459045|7.38905609893065|7.3890560989306495

EXPM1

Synopsis:

  1. EXPM1(numeric_exp)

Input:

float numeric expression

Output: double numeric value

Description: Returns Euler’s number at the power of numeric_exp minus 1 (enumeric_exp - 1).

  1. SELECT E(), EXP(2), EXPM1(2);
  2. E() | EXP(2) | EXPM1(2)
  3. -----------------+----------------+----------------
  4. 2.718281828459045|7.38905609893065|6.38905609893065

FLOOR

Synopsis:

  1. FLOOR(numeric_exp)

Input:

numeric expression

Output: integer or long numeric value

Description: Returns the largest integer less than or equal to numeric_exp.

  1. SELECT FLOOR(125.01), FLOOR(-125.99);
  2. FLOOR(125.01) |FLOOR(-125.99)
  3. ---------------+---------------
  4. 125 |-126

LOG

Synopsis:

  1. LOG(numeric_exp)

Input:

numeric expression

Output: double numeric value

Description: Returns the natural logarithm of numeric_exp.

  1. SELECT EXP(3), LOG(20.085536923187668);
  2. EXP(3) |LOG(20.085536923187668)
  3. ------------------+-----------------------
  4. 20.085536923187668|3.0

LOG10

Synopsis:

  1. LOG10(numeric_exp)

Input:

numeric expression

Output: double numeric value

Description: Returns the base 10 logarithm of numeric_exp.

  1. SELECT LOG10(5), LOG(5)/LOG(10);
  2. LOG10(5) | LOG(5)/LOG(10)
  3. ------------------+-----------------------
  4. 0.6989700043360189|0.6989700043360187

PI

Synopsis:

  1. PI()

Input: none

Output: 3.141592653589793

Description: Returns PI number.

  1. SELECT PI();
  2. PI()
  3. -----------------
  4. 3.141592653589793

POWER

Synopsis:

  1. POWER(
  2. numeric_exp,
  3. integer_exp)

Input:

numeric expression

integer expression

Output: double numeric value

Description: Returns the value of numeric_exp to the power of integer_exp.

  1. SELECT POWER(3, 2), POWER(3, 3);
  2. POWER(3, 2) | POWER(3, 3)
  3. ---------------+---------------
  4. 9.0 |27.0
  1. SELECT POWER(5, -1), POWER(5, -2);
  2. POWER(5, -1) | POWER(5, -2)
  3. ---------------+---------------
  4. 0.2 |0.04

RANDOM/RAND

Synopsis:

  1. RANDOM(seed)

Input:

numeric expression

Output: double numeric value

Description: Returns a random double using the given seed.

  1. SELECT RANDOM(123);
  2. RANDOM(123)
  3. ------------------
  4. 0.7231742029971469

ROUND

Synopsis:

  1. ROUND(
  2. numeric_exp
  3. [, integer_exp])

Input:

numeric expression

integer expression; optional

Output: numeric

Description: Returns numeric_exp rounded to integer_exp places right of the decimal point. If integer_exp is negative, numeric_exp is rounded to |integer_exp| places to the left of the decimal point. If integer_exp is omitted, the function will perform as if integer_exp would be 0. The returned numeric data type is the same as the data type of numeric_exp.

  1. SELECT ROUND(-345.153, 1) AS rounded;
  2. rounded
  3. ---------------
  4. -345.2
  1. SELECT ROUND(-345.153, -1) AS rounded;
  2. rounded
  3. ---------------
  4. -350.0

SIGN/SIGNUM

Synopsis:

  1. SIGN(numeric_exp)

Input:

numeric expression

Output: [-1, 0, 1]

Description: Returns an indicator of the sign of numeric_exp. If numeric_exp is less than zero, –1 is returned. If numeric_exp equals zero, 0 is returned. If numeric_exp is greater than zero, 1 is returned.

  1. SELECT SIGN(-123), SIGN(0), SIGN(415);
  2. SIGN(-123) | SIGN(0) | SIGN(415)
  3. ---------------+---------------+---------------
  4. -1 |0 |1

SQRT

Synopsis:

  1. SQRT(numeric_exp)

Input:

numeric expression

Output: double numeric value

Description: Returns square root of numeric_exp.

  1. SELECT SQRT(EXP(2)), E(), SQRT(25);
  2. SQRT(EXP(2)) | E() | SQRT(25)
  3. -----------------+-----------------+---------------
  4. 2.718281828459045|2.718281828459045|5.0

TRUNCATE/TRUNC

Synopsis:

  1. TRUNCATE(
  2. numeric_exp
  3. [, integer_exp])

Input:

numeric expression

integer expression; optional

Output: numeric

Description: Returns numeric_exp truncated to integer_exp places right of the decimal point. If integer_exp is negative, numeric_exp is truncated to |integer_exp| places to the left of the decimal point. If integer_exp is omitted, the function will perform as if integer_exp would be 0. The returned numeric data type is the same as the data type of numeric_exp.

  1. SELECT TRUNC(-345.153, 1) AS trimmed;
  2. trimmed
  3. ---------------
  4. -345.1
  1. SELECT TRUNCATE(-345.153, -1) AS trimmed;
  2. trimmed
  3. ---------------
  4. -340.0

Trigonometric

ACOS

Synopsis:

  1. ACOS(numeric_exp)

Input:

numeric expression

Output: double numeric value

Description: Returns the arccosine of numeric_exp as an angle, expressed in radians.

  1. SELECT ACOS(COS(PI())), PI();
  2. ACOS(COS(PI())) | PI()
  3. -----------------+-----------------
  4. 3.141592653589793|3.141592653589793

ASIN

Synopsis:

  1. ASIN(numeric_exp)

Input:

numeric expression

Output: double numeric value

Description: Returns the arcsine of numeric_exp as an angle, expressed in radians.

  1. SELECT ROUND(DEGREES(ASIN(0.7071067811865475))) AS "ASIN(0.707)", ROUND(SIN(RADIANS(45)), 3) AS "SIN(45)";
  2. ASIN(0.707) | SIN(45)
  3. ---------------+---------------
  4. 45.0 |0.707

ATAN

Synopsis:

  1. ATAN(numeric_exp)

Input:

numeric expression

Output: double numeric value

Description: Returns the arctangent of numeric_exp as an angle, expressed in radians.

  1. SELECT DEGREES(ATAN(TAN(RADIANS(90))));
  2. DEGREES(ATAN(TAN(RADIANS(90))))
  3. -------------------------------
  4. 90.0

ATAN2

Synopsis:

  1. ATAN2(
  2. ordinate,
  3. abscisa)

Input:

numeric expression

numeric expression

Output: double numeric value

Description: Returns the arctangent of the ordinate and abscisa coordinates specified as an angle, expressed in radians.

  1. SELECT ATAN2(5 * SIN(RADIANS(45)), 5 * COS(RADIANS(45))) AS "ATAN2(5*SIN(45), 5*COS(45))", RADIANS(45);
  2. ATAN2(5*SIN(45), 5*COS(45))| RADIANS(45)
  3. ---------------------------+------------------
  4. 0.7853981633974483 |0.7853981633974483

COS

Synopsis:

  1. COS(numeric_exp)

Input:

numeric expression

Output: double numeric value

Description: Returns the cosine of numeric_exp, where numeric_exp is an angle expressed in radians.

  1. SELECT COS(RADIANS(180)), POWER(SIN(RADIANS(54)), 2) + POWER(COS(RADIANS(54)), 2) AS pythagorean_identity;
  2. COS(RADIANS(180))|pythagorean_identity
  3. -----------------+--------------------
  4. -1.0 |1.0

COSH

Synopsis:

  1. COSH(numeric_exp)

Input:

numeric expression

Output: double numeric value

Description: Returns the hyperbolic cosine of numeric_exp.

  1. SELECT COSH(5), (POWER(E(), 5) + POWER(E(), -5)) / 2 AS "(e^5 + e^-5)/2";
  2. COSH(5) | (e^5 + e^-5)/2
  3. -----------------+-----------------
  4. 74.20994852478785|74.20994852478783

COT

Synopsis:

  1. COT(numeric_exp)

Input:

numeric expression

Output: double numeric value

Description: Returns the cotangent of numeric_exp, where numeric_exp is an angle expressed in radians.

  1. SELECT COT(RADIANS(30)) AS "COT(30)", COS(RADIANS(30)) / SIN(RADIANS(30)) AS "COS(30)/SIN(30)";
  2. COT(30) | COS(30)/SIN(30)
  3. ------------------+------------------
  4. 1.7320508075688774|1.7320508075688776

DEGREES

Synopsis:

  1. DEGREES(numeric_exp)

Input:

numeric expression

Output: double numeric value

Description: Convert from radians to degrees).

  1. SELECT DEGREES(PI() * 2), DEGREES(PI());
  2. DEGREES(PI() * 2)| DEGREES(PI())
  3. -----------------+---------------
  4. 360.0 |180.0

RADIANS

Synopsis:

  1. RADIANS(numeric_exp)

Input:

numeric expression

Output: double numeric value

Description: Convert from degrees) to radians.

  1. SELECT RADIANS(90), PI()/2;
  2. RADIANS(90) | PI()/2
  3. ------------------+------------------
  4. 1.5707963267948966|1.5707963267948966

SIN

Synopsis:

  1. SIN(numeric_exp)

Input:

numeric expression

Output: double numeric value

Description: Returns the sine of numeric_exp, where numeric_exp is an angle expressed in radians.

  1. SELECT SIN(RADIANS(90)), POWER(SIN(RADIANS(67)), 2) + POWER(COS(RADIANS(67)), 2) AS pythagorean_identity;
  2. SIN(RADIANS(90))|pythagorean_identity
  3. ----------------+--------------------
  4. 1.0 |1.0

SINH

Synopsis:

  1. SINH(numeric_exp)

Input:

numeric expression

Output: double numeric value

Description: Returns the hyperbolic sine of numeric_exp.

  1. SELECT SINH(5), (POWER(E(), 5) - POWER(E(), -5)) / 2 AS "(e^5 - e^-5)/2";
  2. SINH(5) | (e^5 - e^-5)/2
  3. -----------------+-----------------
  4. 74.20321057778875|74.20321057778874

TAN

Synopsis:

  1. TAN(numeric_exp)

Input:

numeric expression

Output: double numeric value

Description: Returns the tangent of numeric_exp, where numeric_exp is an angle expressed in radians.

  1. SELECT TAN(RADIANS(66)) AS "TAN(66)", SIN(RADIANS(66))/COS(RADIANS(66)) AS "SIN(66)/COS(66)=TAN(66)";
  2. TAN(66) |SIN(66)/COS(66)=TAN(66)
  3. ------------------+-----------------------
  4. 2.2460367739042164|2.246036773904216