$tanh (aggregation)
$tanh
以弧度为单位返回数值的双曲正切值。
$tanh
采用以下语法:{ $tanh: <expression> } $tanh
接受解析为数字的任何有效表达式,以弧度为单位。 如果表达式返回以度为单位的值,请使用$degreesToRadians
操作符将该值转换为弧度。默认情况下,
$tanh
以double
形式返回值。 如果<expression>
解析为128位十进制值,
$tanh
还可以返回128位十进制值。
有关表达式的更多信息,请参阅表达式运算符。
行为
null
、NaN
和 +/- Infinity
If the input argument resolves to a value of null
or refers to a
field that is missing, $tanh
returns null
. If the
argument resolves to NaN
, $tanh
returns NaN
. If
the argument resolves to negative or positive Infinity
,
$tanh
returns -1
or 1
respectively.
例子 | 结果 |
---|---|
|
|
|
|
|
|
|
|
例子
trigonometry
以下collection包含一个文档,其中存储了一个以度数为单位的angle
值:
db.trigonometry.insertOne( { "_id" : ObjectId( "5c50782193f833234ba90d45" ), "angle" : NumberDecimal( "53.1301023541559787031443874490659" ) } )
The following aggregation operation uses the
$tanh
expression to calculate the hyperbolic
tangent of angle
and adds it to the input document using
the $addFields
pipeline stage:
db.trigonometry.aggregate( [ { $addFields : { "tanh_output" : { $tanh : { $degreesToRadians : "$angle" } } } } ] )
$degreesToRadians
表达式将以度为单位的angle
转换为弧度。
示例输出:
{ "_id" : ObjectId("5c50782193f833234ba90d45"), "angle" : NumberDecimal("53.1301023541559787031443874490659"), "tanh_output" : NumberDecimal("0.7293303448445332820512777329448416") }
以下trigonometry
集合包含一个文档,其中存储了以弧度为单位的angle
值:
db.trigonometry.insertOne( { "_id" : ObjectId( "5c50782193f833234ba90d55" ), "angle" : NumberDecimal( "1.6301023541559787031443874490659" ) } )
The following aggregation operation uses the
$tanh
expression to calculate the hyperbolic
tangent of angle
and adds it to the input document using
the $addFields
pipeline stage:
db.trigonometry.aggregate( [ { $addFields : { "tanh_output" : { $tanh : "$angle" } } } ] )
示例输出:
{ "_id" : ObjectId("5c50782193f833234ba90d55"), "angle" : NumberDecimal("1.6301023541559787031443874490659"), "tanh_output" : NumberDecimal("0.9260761562750713360156803177935379") }