Mathematical functions

Updated at:

The following are the mathematical functions:

Function

Features

ABS

Calculates the absolute value.

CEIL

Rounds a number up to the nearest integer.

FLOOR

Rounds a number down to the nearest integer.

POW

Calculates the power of a number.

ROUND

Rounds a number to a specified number of decimal places.

SQRT

Calculates the square root.

ABS

  • Description

Calculates the absolute value of a number.

  • Parameters

    • number: Required. A numeric type value for which to calculate the absolute value.

  • Return value

Returns the absolute value of number. If number is NULL, this function returns NULL.

  • Supported compute engines

MaxCompute (ODPS), MySQL, RDS, Hive, AnalyticDB for PostgreSQL (ADB_PG), PolarDB-PG, PostgreSQL, and Spark.

CEIL

  • Description

Rounds a number up to the nearest integer that is greater than or equal to the number.

  • Parameters

    • number: Required. The numeric value for the calculation.

  • Return value

Returns the smallest integer that is greater than or equal to number. If number is NULL, this function returns NULL.

  • Supported compute engines

MaxCompute (ODPS), MySQL, RDS, Hive, AnalyticDB for PostgreSQL (ADB_PG), PolarDB-PG, PostgreSQL, and Spark.

FLOOR

  • Description

Rounds a number down to the nearest integer that is less than or equal to the number.

  • Parameters

    • number: Required. Specifies the numeric value for the calculation.

  • Return value

Returns the largest integer that is less than or equal to number. If number is NULL, this function returns NULL.

  • Supported compute engines

MaxCompute (ODPS), MySQL, RDS, Hive, AnalyticDB for PostgreSQL (ADB_PG), PolarDB-PG, PostgreSQL, and Spark.

POW

  • Description

Calculates the value of x raised to the power of y (x^y).

  • Parameters

    • x: Required. A numeric type value that specifies the base.

    • y: Required. A numeric type value that specifies the exponent.

  • Return value

Returns the result of the power calculation. If x or y is NULL, this function returns NULL.

  • Supported compute engines

MaxCompute (ODPS), MySQL, RDS, Hive, AnalyticDB for PostgreSQL (ADB_PG), PolarDB-PG, PostgreSQL, and Spark.

ROUND

  • Description

Rounds a number to a specified number of decimal places.

  • Parameters

    • number: Required. A numeric type value to round.

    • scale: Required. An integer that specifies the number of digits to retain after the decimal point. The default value is 0.

  • Return value

Returns the value of number rounded to the specified number of decimal places. If number is NULL, this function returns NULL.

  • Supported compute engines

MaxCompute (ODPS), MySQL, RDS, Hive, AnalyticDB for PostgreSQL (ADB_PG), PolarDB-PG, PostgreSQL, and Spark.

SQRT

  • Description

Calculates the square root of a number.

  • Parameters

    • number: Required. The numeric value for the calculation.

  • Return value

Returns the square root of number. If number is NULL, this function returns NULL.

  • Supported compute engines

MaxCompute (ODPS), MySQL, RDS, Hive, AnalyticDB for PostgreSQL (ADB_PG), PolarDB-PG, PostgreSQL, and Spark.