$coshRetorna o cosseno hiperbólico de um valor medido em radianos.
$coshtem a seguinte sintaxe:{ $cosh: <expression> } $coshtakes any valid expression that resolves to a number, measured in radians. If the expression returns a value in degrees, use the$degreesToRadiansoperator to convert the value to radians.By default
$coshreturns values as adouble.$coshcan also return values as a 128-bit decimal if the<expression>resolves to a 128-bit decimal value.Para mais informações sobre expressões, consulte Expressões.
Comportamento
null, NaN e +/- Infinity
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.
Exemplo | Resultados |
|---|---|
|
|
|
|
|
|
|
|
Exemplo
A seguinte collection do trigonometry contém um documento que armazena um valor do angle medido em graus:
db.trigonometry.insertOne( { "_id" : ObjectId( "5c50782193f833234ba90d85" ), "angle" : Decimal128( "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" } } } } ] )
A expressão $degreesToRadians converte o angle de graus para radianos.
Saída de exemplo:
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "angle" : Decimal128("53.1301023541559787031443874490659"), "cosh_output" : Decimal128("1.461642741099671277595921778079396") }
Because angle is stored as a 128-bit decimal, the $cosh output is also a 128-bit decimal.
A seguinte coleção trigonometry contém um documento que armazena um valor angle medido em radianos:
db.trigonometry.insertOne( { "_id" : ObjectId( "5c50782193f833234ba90d15" ), "angle" : Decimal128( "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" } } } ] )
Saída de exemplo:
{ "_id" : ObjectId("5c50782193f833234ba90d15"), "angle" : Decimal128("1.6301023541559787031443874490659"), "cosh_output" : Decimal128("2.650153334504361016712328539738000") }
Because angle is stored as a 128-bit decimal, the $cosh output is also a 128-bit decimal.