Mathematical Functions and Operators
Mathematical functions and operators evaluate to a numeric value on one or two input expressions.
Currently, Extreme DPS allows only numeric types to be used as input of mathematical functions and operators.
Mathematical operators
The following table lists the mathematical operators supported by Extreme DPS. Note that the return type of a mathematical operator is the same as the input type.
Operator | Syntax | Description |
---|---|---|
+ | a + b | Adds a to b. |
- | a - b | Subtracts b from a. |
* | a * b | Mutiplies a by b. |
/ | a / b | Divides a by b. |
% | a % b | Computes the modulo of a per b. It is equivalent to MOD . |
Mathematical functions
The following table lists the mathematical functions supported by Extreme DPS. Some functions are provided in multiple forms that vary with the argument types. numeric
in the following table indicates any numeric type supported by Extreme DPS, namely bigint
, integer
, smallint
, double precision
, real
, and decimal
.
Function | Return type | Description | Example | Result |
---|---|---|---|---|
abs(numeric) | Same as input | Returns the absolute value of the given expression. | abs(-3.5) | 3.5 |
cbrt(double precision) | double precision | Returns the cube root of the given expression. | cbrt(75.0) | 5 |
ceil(double precision) | double precision | Returns the nearest integer that is greater than or equal to the given expression. | ceil(-3.5) | -3 |
ceiling(double precision) | double precision | Returns the nearest integer that is greater than or equal to the given expression. | ceiling(-3.5) | -3 |
degrees(double precision) | double precision | Converts radians to degrees. | degrees(0.5) | 28.6478897565412 |
exp(double precision) | double precision | Returns the exponential of the given expression. | exp(1.0) | 2.71828182845905 |
floor(double precision) | double precision | Returns the nearest integer that is less than or equal to the expression. | floor(-42.8) | -43 |
ln(double precision) | double precision | Returns the natural logarithm of the given expression. | ln(2.0) | 0.693147180559945 |
log(double precision) | double precision | Returns the logarithm of the given expression. | log(100.0) | 2 |
log10(double precision) | double precision | Returns the base-10 logarithm of the given expression. | log10(100.0) | 2 |
mod(y, x) | Same as input | Returns the remainder after <y> is divided by <x> . <y> and <x> can be any numeric type, except decimal . | mod(9, 4) | 1 |
pi() | double precision | Returns 3.14159265358979 which is the mathematical constant of pi, accurate to 15 digits. | pi() | 3.14159265358979 |
power (a double precision, b double precision) | double precision | Returns <a> raised to the power of <b> . | power(9.0, 3.0) | 729 |
radians(double precision) | double precision | Converts degrees to radians. | radians(45.0) | 0.785398163397448 |
round(double precision or decimal) | Same as input | Rounds the expression to the nearest integer. | round(42.4) | 42 |
round(v decimal, s integer) | decimal | Rounds <v> to <s> decimal places. | round(42.4382, 2) | 42.44 |
sign(double precision) | decimal | Returns the sign of the argument. -1 indicates negative, 1 indicates positive, 0 indicates 0. | sign(-8.4) | -1 |
sqrt(double precision) | decimal | Returns the square root of the argument. | sqrt(2.0) | 1.4142135623731 |
trunc(double precision or decimal) | decimal | Rounds the argument down to the nearest or equal integer closer to zero. | trunc(42.8) | 42 |
trunc(v numeric, s integer) | decimal | Round the argument down to <s> decimal places. | trunc(42.4382, 2) | 42.43 |
width_bucket(operand double precision, b1 double precision, b2 double precision, count integer) | integer | Returns the bucket number of 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 range. | width_bucket(5.35, 0.024, 10.06, 5) | 3 |
For all mathematical functions except abs
, decimal
cannot be used as the input.
Random functions
Currently, Extreme DPS allows you to use random()
to generate random double precision
numbers that range from 0.0
to 1.0
.
Function random()
uses a simple linear congruential algorithm. It is fast but not suitable for cryptographic applications.
Trigonometric functions
The following table lists the trigonometric functions provided by Extreme DPS.
The input types of the following trigonometric functions can only be double precision
and the return type of each is double precision
.
Function | Description | Example | Result |
---|---|---|---|
ACOS(radians) | Returns the arc cosine in radians of the argument. | ACOS(0) | 1.5707963267948966 |
ACOSD(degrees) | Returns the arc cosine in degrees of the argument. | ACOSD(0) | 90 |
ASIN(radians) | Returns the arc sine in radians of the argument. | ASIN(0) | 0 |
ASIND(degrees) | Returns the arc sine in degrees of the argument. | ASIND(0) | 0 |
ATAN(radians) | Returns the arc tangent in radians of the argument. | ATAN(0) | 0 |
ATAND(degrees) | Returns the arc tangent in degrees of the argument. | ATAND(0) | 0 |
ATAN2(y radians, x radians) | Returns the arc tangent in radians of y/x. | ATAN2(0,0) | 0 |
ATAN2D(y degrees, x degrees) | Returns the arc tangent in degrees of y/x. | ATAN2D(0,0) | 0 |
COS(radians) | Returns the cosine in radians of the argument. | COS(0) | 1 |
COSD(degrees) | Returns the cosine in degrees of the argument. | COSD(0) | 1 |
COT(radians) | Returns the cosine in radians of the argument. | COT(PI/4) | 1 |
COTD(degrees) | Returns the cosine in degrees of the argument. | COTD(-45) | -1 |
SIN(radians) | Returns the sine in radians of the argument. | SIN(0) | 0 |
SIND(degrees) | Returns the sine in degrees of the argument. | SIND(0) | 0 |
TAN(radians) | Returns the tangent in radians of the argument. | TAN(0) | 0 |
TAND(degrees) | Returns the tangent in degrees of the argument. | TAND(0) | 0 |
Hyperbolic functions
The following table lists the hyperbolic functions provided by Extreme DPS.
The input types of the following hyperbolic functions can only be double precision
and the return type of each is double precision
.
Function | Description | Example | Result |
---|---|---|---|
SINH(double precision) | Returns the hyperbolic sine of the argument. | SINH(0) | 1 |
COSH(double precision) | Returns the hyperbolic cosine of the argument. | COSH(0) | 1 |
TANH(double precision) | Returns the hyperbolic tangent of the argument. | TANH(0) | 0 |
ASINH(double precision) | Returns the hyperbolic sine of the argument. | ASINH(0) | 0 |
ACOSH(double precision) | Returns the hyperbolic cosine of the argument. | ACOSH(1) | 0 |
ATANH(double precision) | Returns the hyperbolic tangent of the argument. | ATANH(0) | 0 |