Skip to main content

Mathematical Functions

Scalar functions for mathematical operations and calculations that can be used in any expression context.

abs(x)

Returns the absolute value of a number.

Parameters

  • x - Numeric expression

Description

The abs() function returns the absolute value (magnitude) of the input number, removing any negative sign. For positive numbers and zero, it returns the value unchanged. For negative numbers, it returns the positive equivalent.

cbrt(x)

Returns the cube root of a number.

Parameters

  • x - Numeric expression

Description

The cbrt() function calculates the cube root of the input value. The result is always returned as a double-precision floating-point number. Unlike square root, cube root is defined for negative numbers.

ceil(x)

Rounds a number up to the nearest integer.

Parameters

  • x - Numeric expression

Description

The ceil() function rounds the input value up to the nearest integer. For positive numbers, this means rounding away from zero. For negative numbers, this means rounding toward zero.

degrees(x)

Converts radians to degrees.

Parameters

  • x - Numeric expression representing an angle in radians

Description

The degrees() function converts an angle from radians to degrees. The result is always returned as a double-precision floating-point number. The conversion uses the formula: degrees = radians × (180/π).

e()

Returns Euler's number (mathematical constant e).

Parameters

This function takes no parameters.

Description

The e() function returns the mathematical constant e (approximately 2.71828), which is the base of natural logarithms. The result is returned as a double-precision floating-point number.

exp(x)

Returns e raised to the power of x.

Parameters

  • x - Numeric expression representing the exponent

Description

The exp() function calculates e^x, where e is Euler's number. This is the exponential function, which is the inverse of the natural logarithm. The result is always returned as a double-precision floating-point number.

floor(x)

Rounds a number down to the nearest integer.

Parameters

  • x - Numeric expression

Description

The floor() function rounds the input value down to the nearest integer. For positive numbers, this means rounding toward zero. For negative numbers, this means rounding away from zero.

ln(x)

Returns the natural logarithm of a number.

Parameters

  • x - Numeric expression (must be positive)

Description

The ln() function calculates the natural logarithm (base e) of the input value. The input must be positive; negative values or zero will result in an error. The result is always returned as a double-precision floating-point number.

log(b, x)

Returns the logarithm of x with the specified base.

Parameters

  • b - Numeric expression representing the logarithm base
  • x - Numeric expression (must be positive)

Description

The log() function calculates the logarithm of x using the specified base b. Both the base and the value must be positive. The result is always returned as a double-precision floating-point number.

log10(x)

Returns the base-10 logarithm of a number.

Parameters

  • x - Numeric expression (must be positive)

Description

The log10() function calculates the common logarithm (base 10) of the input value. The input must be positive; negative values or zero will result in an error. The result is always returned as a double-precision floating-point number.

log2(x)

Returns the base-2 logarithm of a number.

Parameters

  • x - Numeric expression (must be positive)

Description

The log2() function calculates the binary logarithm (base 2) of the input value. The input must be positive; negative values or zero will result in an error. The result is always returned as a double-precision floating-point number.

pi()

Returns the mathematical constant π (pi).

Parameters

This function takes no parameters.

Description

The pi() function returns the mathematical constant π (approximately 3.14159), which represents the ratio of a circle's circumference to its diameter. The result is returned as a double-precision floating-point number.

pow(x, p)

Raises a number to the specified power.

Parameters

  • x - Numeric expression representing the base
  • p - Numeric expression representing the exponent

Description

The pow() function calculates x raised to the power of p (x^p). The result is always returned as a double-precision floating-point number.

radians(x)

Converts degrees to radians.

Parameters

  • x - Numeric expression representing an angle in degrees

Description

The radians() function converts an angle from degrees to radians. The result is always returned as a double-precision floating-point number. The conversion uses the formula: radians = degrees × (π/180).

round(x) / round(x, d)

Rounds a number to the nearest integer or specified decimal places.

Parameters

  • x - Numeric expression to round
  • d (optional) - Integer specifying the number of decimal places

Description

The round() function rounds the input value to the nearest integer when used with one parameter, or to the specified number of decimal places when used with two parameters. The rounding follows standard mathematical rules (0.5 rounds up).

sign(x)

Returns the sign of a number.

Parameters

  • x - Numeric expression

Description

The sign() function returns -1 for negative numbers, 0 for zero, and 1 for positive numbers. This function helps determine the sign of a value without regard to its magnitude.

sqrt(x)

Returns the square root of a number.

Parameters

  • x - Numeric expression (must be non-negative)

Description

The sqrt() function calculates the square root of the input value. The input must be non-negative; negative values will result in an error. The result is always returned as a double-precision floating-point number.

truncate(x)

Removes the fractional part of a number.

Parameters

  • x - Numeric expression

Description

The truncate() function removes the fractional part of a number, effectively rounding toward zero. For positive numbers, this is equivalent to floor(). For negative numbers, this is equivalent to ceil().

width_bucket(x, bound1, bound2, n)

Returns the bucket number for a value in a histogram with equal-width buckets.

Parameters

  • x - Numeric expression representing the value to bucket
  • bound1 - Numeric expression representing the lower bound
  • bound2 - Numeric expression representing the upper bound
  • n - Integer expression representing the number of buckets

Description

The width_bucket() function determines which bucket a value falls into when dividing the range between bound1 and bound2 into n equal-width buckets. Values outside the bounds return 0 (below bound1) or n+1 (above bound2).

width_bucket(x, bins)

Returns the bucket number for a value using explicitly defined bucket boundaries.

Parameters

  • x - Numeric expression representing the value to bucket
  • bins - Array of numeric values representing bucket boundaries

Description

The width_bucket() function determines which bucket a value falls into using an array of explicitly defined bucket boundaries. The function returns the index of the bucket where the value belongs, with 0 for values below the lowest boundary and array length + 1 for values above the highest boundary.