- Reference >
- Operators >
- Aggregation Pipeline Operators >
- $cosh (aggregation)
$cosh (aggregation)¶
-
$cosh¶ New in version 4.2.
Returns the hyperbolic cosine of a value that is measured in radians.
$coshhas the following syntax:$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.For more information on expressions, see Expressions.
Behavior¶
null, NaN, and +/- 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.
| Example | Results |
|---|---|
{ $cosh: NaN } |
NaN |
{ $cosh: null } |
null |
{ $cosh: -Infinity } |
Infinity |
{ $cosh: Infinity } |
Infinity |
Example¶
- Hyperbolic Cosine in Degrees
- Hyperbolic Cosine in Radians
The following trigonometry collection contains a document
that stores an angle value measured in degrees:
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:
The $degreesToRadians expression converts the
angle in degrees to radians.
Example output:
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:
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:
Example output:
Because angle is stored as a 128-bit decimal, the $cosh output is also
a 128-bit decimal.