On this page本页内容
$cosh
New in version 4.2.在版本4.2中新增。
Returns the hyperbolic cosine of a value that is measured in radians.返回以弧度度量的值的双曲余弦。
$cosh has the following syntax:语法如下:
{ $cosh: <expression> }
$cosh takes any valid expression that resolves to a number, measured in radians. 采用解析为数字的任何有效表达式,以弧度为单位。If the expression returns a value in degrees, use the 如果表达式返回以度为单位的值,请使用$degreesToRadians operator to convert the value to radians.$degreesToRadians运算符将该值转换为弧度。
By default 默认情况下,$cosh returns values as a double. $cosh以double返回值。如果$cosh can also return values as a 128-bit decimal if the <expression> resolves to a 128-bit decimal value.<expression>解析为128位十进制值,$cosh也可以以128位十进制返回值。
For more information on expressions, see Expressions.有关表达式的详细信息,请参阅表达式。
null, NaN, and +/- InfinityIf the input argument resolves to a value of 如果输入参数解析为null or refers to a field that is missing, $cosh returns null. null值或引用缺少的字段,$cosh返回null。If the argument resolves to 如果参数解析为NaN, $cosh returns NaN. NaN,$cosh返回NaN。If the argument resolves to negative or positive 如果参数解析为负或正Infinity, $cosh returns positive Infinity.Infinity,$cosh返回正无穷大。
{ $cosh: NaN } | NaN |
{ $cosh: null } | null |
{ $cosh: -Infinity } | Infinity |
{ $cosh: Infinity } | Infinity |
The following trigonometry collection contains a document
that stores an angle value measured in degrees:
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" } } } } ] )
The $degreesToRadians expression converts the
angle in degrees to radians.
Example output:
{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"angle" : NumberDecimal("53.1301023541559787031443874490659"),
"cosh_output" : NumberDecimal("1.461642741099671277595921778079396")
}Because angle is stored as a 128-bit decimal, the $cosh output is also a
128-bit decimal.
The following trigonometry collection contains a document
that stores an angle value measured in radians:
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" } } } ] )
Example output:
{
"_id" : ObjectId("5c50782193f833234ba90d15"),
"angle" : NumberDecimal("1.6301023541559787031443874490659"),
"cosh_output" : NumberDecimal("2.650153334504361016712328539738000")
}Because angle is stored as a 128-bit decimal, the $cosh output is also
a 128-bit decimal.