Docs 菜单

$cosh (aggregation)

在此页面上

$cosh

Returns the hyperbolic cosine of a value that is measured in radians.

$cosh 采用以下语法:

{ $cosh: <expression> }

$cosh接受解析为数字的任何有效表达式,以弧度为单位。 如果表达式返回以度为单位的值,请使用$degreesToRadians操作符将该值转换为弧度。

默认情况下, $coshdouble形式返回值。 如果<expression>解析为128位十进制值, $cosh还可以返回128位十进制值。

有关表达式的更多信息,请参阅表达式运算符。

If the input argument resolves to a value of null or refers to a field that is missing, $cosh returns null. If the argument resolves to NaN, $cosh returns NaN. If the argument resolves to negative or positive Infinity, $cosh returns positive Infinity.

例子
结果

{ $cosh: NaN }

NaN

{ $cosh: null }

null

{ $cosh: -Infinity }

Infinity

{ $cosh: Infinity }

Infinity

trigonometry以下collection包含一个文档,其中存储了一个以度数为单位的angle 值:

db.trigonometry.insertOne(
{
"_id" : ObjectId( "5c50782193f833234ba90d85" ),
"angle" : NumberDecimal( "53.1301023541559787031443874490659" )
}
)

The following aggregation operation uses the $cosh expression to calculate the hyperbolic cosine of angle and adds it to the input document using the $addFields pipeline stage:

db.trigonometry.aggregate( [
{
$addFields : {
"cosh_output" : { $cosh : { $degreesToRadians : "$angle" } }
}
}
] )

$degreesToRadians表达式将以度为单位的angle转换为弧度。

示例输出:

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"angle" : NumberDecimal("53.1301023541559787031443874490659"),
"cosh_output" : NumberDecimal("1.461642741099671277595921778079396")
}

由于angle存储为128位十进制数,因此$cosh输出也是128位十进制数。

以下trigonometry集合包含一个文档,其中存储了以弧度为单位的angle值:

db.trigonometry.insertOne(
{
"_id" : ObjectId( "5c50782193f833234ba90d15" ),
"angle" : NumberDecimal( "1.6301023541559787031443874490659" )
}
)

The following aggregation operation uses the $cosh expression to calculate the hyperbolic cosine of angle and adds it to the input document using the $addFields pipeline stage:

db.trigonometry.aggregate( [
{
$addFields : {
"cosh_output" : { $cosh : "$angle" }
}
}
] )

示例输出:

{
"_id" : ObjectId("5c50782193f833234ba90d15"),
"angle" : NumberDecimal("1.6301023541559787031443874490659"),
"cosh_output" : NumberDecimal("2.650153334504361016712328539738000")
}

由于angle存储为128位十进制数,因此$cosh输出也是128位十进制数。

在此页面上