数学函数

• 如果任一输入参数为 `NULL`，则返回 `NULL`
• 如果任一参数为 `NaN`，则返回 `NaN`

ABS

``````ABS(X)
``````

INPUTINT64NUMERICFLOAT64

SIGN

``````SIGN(X)
``````

INPUTINT64NUMERICFLOAT64

IS_INF

``````IS_INF(X)
``````

`NUMERIC` 输入返回 `FALSE`，因为 `NUMERIC` 不能为 `INF`

`NULL` 输入返回 `NULL`

IS_NAN

``````IS_NAN(X)
``````

`NUMERIC` 输入返回 `FALSE`，因为 `NUMERIC` 不能为 NAN。

`NULL` 输入返回 `NULL`

IEEE_DIVIDE

``````IEEE_DIVIDE(X, Y)
``````

• 如果结果溢出，则返回 `+/-inf`
• 如果 Y= 0 且 X = 0，则返回 `NaN`
• 如果 Y = 0 且 X != 0，则返回 `+/-inf`
• 如果 X = `+/-inf` 且 Y = `+/-inf`，则返回 `NaN`

`IEEE_DIVIDE` 的特殊情况

0 0 `NaN`
0 `NaN` `NaN`
`NaN` 0 `NaN`
`+/-inf` `+/-inf` `NaN`

SQRT

``````SQRT(X)
``````

POW

``````POW(X, Y)
``````

• X 是小于 0 的有限值且 Y 是非整数
• X 是 0 且 Y 是小于 0 的有限值

INPUTINT64NUMERICFLOAT64
INT64FLOAT64NUMERICFLOAT64
NUMERICNUMERICNUMERICFLOAT64
FLOAT64FLOAT64FLOAT64FLOAT64

`POW(X, Y)` 的特殊情况

X Y POW(X, Y) 或 POWER(X, Y)
1.0 任何值（包括 `NaN` 1.0

-1.0 `+/-inf` 1.0
ABS(X) < 1 `-inf` `+inf`
ABS(X) > 1 `-inf` 0
ABS(X) < 1 `+inf` 0
ABS(X) > 1 `+inf` `+inf`
`-inf` Y < 0 0
`-inf` Y > 0 如果 Y 为奇整数，则为 `-inf`；否则为 `+inf`
`+inf` Y < 0 0
`+inf` Y > 0 `+inf`

POWER

``````POWER(X, Y)
``````

EXP

``````EXP(X)
``````

LN

``````LN(X)
``````

LOG

``````LOG(X [, Y])
``````

• X 小于或等于 0
• Y 等于 1.0
• Y 小于或等于 0。

`LOG(X, Y)` 的特殊情况

X Y LOG(X, Y)
`-inf` 任意值 `NaN`

`+inf` 0.0 Y < 1.0 `-inf`
`+inf` Y > 1.0 `+inf`

LOG10

``````LOG10(X)
``````

`LOG` 类似，但计算的是以 10 为底数的对数。

GREATEST

``````GREATEST(X1,...,XN)
``````

LEAST

``````LEAST(X1,...,XN)
``````

DIV

``````DIV(X, Y)
``````

INPUTINT64NUMERIC
INT64INT64NUMERIC
NUMERICNUMERICNUMERIC

SAFE_DIVIDE

``````SAFE_DIVIDE(X, Y)
``````

INPUTINT64NUMERICFLOAT64
INT64FLOAT64NUMERICFLOAT64
NUMERICNUMERICNUMERICFLOAT64
FLOAT64FLOAT64FLOAT64FLOAT64

SAFE_MULTIPLY

``````SAFE_MULTIPLY(X, Y)
``````

INPUTINT64NUMERICFLOAT64
INT64INT64NUMERICFLOAT64
NUMERICNUMERICNUMERICFLOAT64
FLOAT64FLOAT64FLOAT64FLOAT64

SAFE_NEGATE

``````SAFE_NEGATE(X)
``````

INPUTINT64NUMERICFLOAT64

``````SAFE_ADD(X, Y)
``````

INPUTINT64NUMERICFLOAT64
INT64INT64NUMERICFLOAT64
NUMERICNUMERICNUMERICFLOAT64
FLOAT64FLOAT64FLOAT64FLOAT64

SAFE_SUBTRACT

``````SAFE_SUBTRACT(X, Y)
``````

INPUTINT64NUMERICFLOAT64
INT64INT64NUMERICFLOAT64
NUMERICNUMERICNUMERICFLOAT64
FLOAT64FLOAT64FLOAT64FLOAT64

MOD

``````MOD(X, Y)
``````

INPUTINT64NUMERIC
INT64INT64NUMERIC
NUMERICNUMERICNUMERIC

ROUND

``````ROUND(X [, N])
``````

TRUNC

``````TRUNC(X [, N])
``````

CEIL

``````CEIL(X)
``````

CEILING

``````CEILING(X)
``````

FLOOR

``````FLOOR(X)
``````

舍入函数行为示例

Cloud Spanner SQL 舍入函数的行为示例：

2.0 2.0 2.0 2.0 2.0
2.3 2.0 2.0 3.0 2.0
2.8 3.0 2.0 3.0 2.0
2.5 3.0 2.0 3.0 2.0
-2.3 -2.0 -2.0 -2.0 -3.0
-2.8 -3.0 -2.0 -2.0 -3.0
-2.5 -3.0 -2.0 -2.0 -3.0
0 0 0 0 0
`+/-inf` `+/-inf` `+/-inf` `+/-inf` `+/-inf`
`NaN` `NaN` `NaN` `NaN` `NaN`

COS

``````COS(X)
``````

COSH

``````COSH(X)
``````

ACOS

``````ACOS(X)
``````

ACOSH

``````ACOSH(X)
``````

SIN

``````SIN(X)
``````

SINH

``````SINH(X)
``````

ASIN

``````ASIN(X)
``````

ASINH

``````ASINH(X)
``````

TAN

``````TAN(X)
``````

TANH

``````TANH(X)
``````

ATAN

``````ATAN(X)
``````

ATANH

``````ATANH(X)
``````

ATAN2

``````ATAN2(Y, X)
``````

`ATAN2()` 的特殊情况

Y X ATAN2(Y, X)
`NaN` 任意值 `NaN`

0 0 0、π 或 -π（取决于 X 和 Y 的符号）

`+/-inf` 有限值 π/2 或 π/2（取决于 Y 的符号）
`+/-inf` `-inf` ¾π 或 -¾π（取决于 Y 的符号）
`+/-inf` `+inf` π/4 或 -π/4（取决于 Y 的符号）

三角函数和双曲线舍入函数的特殊情况

X COS(X) COSH(X) ACOS(X) ACOSH(X) SIN(X) SINH(X) ASIN(X) ASINH(X) TAN(X) TANH(X) ATAN(X) ATANH(X)
`+/-inf` `NaN` `=+inf` `NaN` `=+inf` `NaN` `=+inf` `NaN` `=+inf` `NaN` =+1.0 π/2 `NaN`
`-inf` `NaN` `=+inf` `NaN` `NaN` `NaN` `-inf` `NaN` `-inf` `NaN` -1.0 -π/2 `NaN`
`NaN` `NaN` `NaN` `NaN` `NaN` `NaN` `NaN` `NaN` `NaN` `NaN` `NaN` `NaN` `NaN`
[{ "type": "thumb-down", "id": "hardToUnderstand", "label":"Hard to understand" },{ "type": "thumb-down", "id": "incorrectInformationOrSampleCode", "label":"Incorrect information or sample code" },{ "type": "thumb-down", "id": "missingTheInformationSamplesINeed", "label":"Missing the information/samples I need" },{ "type": "thumb-down", "id": "translationIssue", "label":"Translation issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]