Skip to main content

数学函数和运算符

数学运算符

运算符表达式 & 描述示例
+operand1 + operand2
加。
1 + 2 → 3
-operand1 - operand2
减。
1 - 2 → -1
-- operand
取反。
- (-1) → 1
*operand1 * operand2
乘。
2 * 3 → 6
/operand1 / operand2
除(对于整型,结果将截断)。
3 / 2 → 1
3.0 / 2 → 1.5
3 / 1.8 → 1.666...
%operand1 % operand2
取余(适用于 smallint/int/bigint/numeric)。
3 % 2 → 1
^operand1 ^ operand2
指数。
2.0 ^ -2 → 0.25
||/||/ operand
立方根。
||/ 27 → 3
@@ operand
绝对值。
@ -10 → 10
&operand1 & operand2
按位与(AND)
91 & 15 → 11
|operand1 | operand2
按位或(OR)
32 | 3 → 35
#operand1 # operand2
按位异或(exclusive OR)
17 # 5 → 20
~~ operand
按位非(NOT)
~1 → -2
<<operand1 << operand2
按位左移
1 << 4 → 16
>>operand1 >> operand2
按位右移
8 >> 2 → 2

数学函数

函数描述示例
abs ( input_value ) → absolute_value
@ ( input_value ) → absolute_value
可返回 input_value 的绝对值。input_value 的类型可以是 int 或 decimal。返回类型与 input_value 类型相同。abs(-3) → 3
@(-3) → 3
cbrt ( double_precision_input ) → double_precision_output可返回输入值的立方根。cbrt(27) → 3
ceil ( numeric_input ) → integer_output
ceil ( double_precision_input ) → integer_output
可返回大于或等于参数的最接近的整数。ceiling()也可以用作ceil()的别名。ceil(1.23559) → 2
ceiling(-1.23559) → -1
exp ( double_precision_input ) → double_precision_output
exp ( numeric_input ) → numeric_output
可返回 numeric 的指数(e 的给定次方)。exp(2.0) → 7.38905609893065
floor ( numeric_input ) → integer_output
floor ( double_precision_input ) → integer_output
可返回小于或等于参数的最接近的整数。floor(1.23559) → 1
floor(-1.23559) → -2
ln ( double_precision_input ) → double_precision_output
ln ( numeric_input ) → numeric_output
可返回输入值的自然对数值。ln(10) → 2.302585092994046
log10 ( double_precision_input ) → double_precision_output
log10 ( numeric_input ) → numeric_output
可返回输入值的以 10 为底的对数值。也可以使用 log(),并接受相同的输入类型。log10(25) → 1.3979400086720377
min_scale ( numeric_input ) → integer_output可精确表示输入值所需的最小刻度(小数点后的位数)min_scale(8.4100) → 2
pow ( x_double_precision, y_double_precision ) → double_precision
pow ( x_numeric, y_numeric ) → numeric
可返回 x_double_precisionx_numericy_double_precisiony_numeric 次幂。power() 也可用作 pow() 的别名。pow(2.0, 3.0) → 8
power(2.0, 3.0) → 8
round ( x_numeric, y_int ) → output_value可将 x_numeric 四舍五入到 y_int 小数位。y_int 可以是负数。round(1.23559, 2) → 1.24
round ( numeric_input ) → integer_output
round ( double_precision_input ) → integer_output
可四舍五入到最接近的整数。round(1.23559) → 1
scale ( numeric_input ) → integer_output参数的刻度(小数点后的位数)scale(8.4100) → 4
sign(double_precision_input or decimal_input) -> same_as_input如果输入值为负数,则返回输入值的符号 -1;如果输入值为正数,则返回输入值的符号 1;如果输入值为 0,则返回输入值的符号 0。sign(8.64) → 1
sign(-8.64) → -1
sqrt ( numeric_input ) → numeric_output
sqrt ( double_precision_input ) → double_precision_output
可返回输入值的平方根。sqrt(16) → 4
trim_scale ( numeric_input ) → numeric_output可通过删除尾数部分的零来降低值的刻度(小数位数)。trim_scale(8.4100) → 8.41
trunc ( double_precision_input ) → double_precision_output
trunc ( numeric_input ) → numeric_output
可截断输入值的小数部分。trunc(-20.0932) → -20

三角函数

函数描述示例
sin ( radians ) → sine可返回角度的三角正弦值(双精度),参数为弧度(双精度)。sin(1) → 0.8414709848078965
cos ( radians ) → cosine可返回角度的三角余弦值(双精度),参数为弧度(双精度)。cos(1) → 0.5403023058681398
tan ( radians ) → tangent可返回角度的三角正切值(双精度),参数为弧度(双精度)。tan(1) → 1.5574077246549021
cot ( radians ) → cotangent可返回角度的三角余切值(双精度),参数为弧度(双精度)。cot(1) → 0.6420926159343308
asin ( input_value ) → radians可返回给定值(双精度)的反正弦值,结果为弧度(双精度)。asin(0.5) → 0.5235987755982989
acos ( input_value ) → radians可返回给定值(双精度)的反余弦值,结果为弧度(双精度)。acos(0.5) → 1.0471975511965976
atan ( input_value ) → radians可返回给定值(双精度)的反切值,结果为弧度(双精度)。atan(1.0) → 0.7853981633974483
atan2 ( y_value, x_value ) → radians可返回两个给定值商(y_value 除以 x_value)的反正切值,结果为弧度(双精度)。atan2(1.0, 1.0) → 0.7853981633974483
sinh ( input_value ) → hyperbolic_sine可返回给定值(双精度)的双曲正弦值(双精度)。sinh(1.0) → 1.1752011936438014
cosh ( input_value ) → hyperbolic_cosine可返回给定值(双精度)的双曲余弦值(双精度)。cosh(1.0) → 1.5430806348152437
tanh ( input_value ) → hyperbolic_tangent可返回给定值(双精度)的双曲正切值(双精度)。tanh(1.0) → 0.7615941559557649
coth ( input_value ) → hyperbolic_cotangent可返回给定值(双精度)的双曲余切值(双精度)。coth(2) → 1.0373147207275481
asinh ( input_value ) → inverse_hyperbolic_sine可返回给定值(双精度)的反双曲正弦值(双精度)。asinh(1.0) → 0.881373587019543
acosh ( input_value ) → inverse_hyperbolic_cosine可返回给定值(双精度)的反双曲余弦值(双精度)。acosh(2.0) → 1.3169578969248166
atanh ( input_value ) → inverse_hyperbolic_tangent可返回给定值(双精度)的反双曲正切值(双精度)。atanh(0.5) → 0.5493061443340549
sind ( degrees ) → sine可返回角度的三角正弦值(双精度),参数为度数(双精度)。sind(15) → 0.2588190451025208
cosd ( degrees ) → cosine可返回角度的三角余弦值(双精度),参数为度数(双精度)。cosd(15) → 0.9659258262890683
tand ( degrees ) → tangent可返回角度的三角正切值(双精度),参数为度数(双精度)。tand(15) → 0.26794919243112275
cotd ( degrees ) → cotangent可返回角度的三角余切值(双精度),参数为度数(双精度)。cotd(45) → 1

度数和弧度函数

函数描述示例
degrees ( radians ) → degrees可将弧度(双精度)转换为角度(双精度)。degrees(pi()/2) → 90
radians ( degrees ) → radians将角度(双精度)转换为弧度(双精度)。radians(180) → 3.141592653589793