|
| 1 | +=================== |
| 2 | +$cosh (aggregation) |
| 3 | +=================== |
| 4 | + |
| 5 | +.. default-domain:: mongodb |
| 6 | + |
| 7 | +.. contents:: On this page |
| 8 | + :local: |
| 9 | + :backlinks: none |
| 10 | + :depth: 1 |
| 11 | + :class: singlecol |
| 12 | + |
| 13 | +.. expression:: $cosh |
| 14 | + |
| 15 | + .. versionadded:: 4.2 |
| 16 | + |
| 17 | + Returns the hyperbolic cosine of a value that is measured in radians. |
| 18 | + |
| 19 | + :expression:`$cosh` has the following syntax: |
| 20 | + |
| 21 | + .. code-block:: javascript |
| 22 | + |
| 23 | + { $cosh: <expression> } |
| 24 | + |
| 25 | + :expression:`$cosh` takes any valid :ref:`expression |
| 26 | + <aggregation-expressions>` that resolves to a number, measured in |
| 27 | + radians. If the expression returns a value in degrees, use the |
| 28 | + :expression:`$degreesToRadians` operator to convert the value to |
| 29 | + radians. |
| 30 | + |
| 31 | + By default :expression:`$cosh` returns values as a ``double``. |
| 32 | + :expression:`$cosh` can also return values as a :ref:`128-bit decimal |
| 33 | + <shell-type-decimal>` if the ``<expression>`` resolves to a 128-bit |
| 34 | + decimal value. |
| 35 | + |
| 36 | + For more information on expressions, see |
| 37 | + :ref:`aggregation-expressions`. |
| 38 | + |
| 39 | +Behavior |
| 40 | +-------- |
| 41 | + |
| 42 | +``null``, ``NaN``, and ``+/- Infinity`` |
| 43 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 44 | + |
| 45 | +If the input argument resolves to a value of ``null`` or refers to a |
| 46 | +field that is missing, :expression:`$cosh` returns ``null``. If the |
| 47 | +argument resolves to ``NaN``, :expression:`$cosh` returns ``NaN``. If |
| 48 | +the argument resolves to negative or positive ``Infinity``, |
| 49 | +:expression:`$cosh` returns positive ``Infinity``. |
| 50 | + |
| 51 | +.. list-table:: |
| 52 | + :header-rows: 1 |
| 53 | + :widths: 50 50 |
| 54 | + |
| 55 | + * - Example |
| 56 | + - Results |
| 57 | + |
| 58 | + * - ``{ $cosh: NaN }`` |
| 59 | + - ``NaN`` |
| 60 | + |
| 61 | + * - ``{ $cosh: null }`` |
| 62 | + - ``null`` |
| 63 | + |
| 64 | + * - ``{ $cosh: -Infinity }`` |
| 65 | + - ``Infinity`` |
| 66 | + |
| 67 | + * - ``{ $cosh: Infinity }`` |
| 68 | + - ``Infinity`` |
| 69 | + |
| 70 | +Example |
| 71 | +------- |
| 72 | + |
| 73 | +.. tabs:: |
| 74 | + |
| 75 | + tabs: |
| 76 | + |
| 77 | + - id: degrees |
| 78 | + name: Hyperbolic Cosine of Value in Degrees |
| 79 | + content: | |
| 80 | + |
| 81 | + The following ``trigonometry`` collection contains a document |
| 82 | + that stores an ``angle`` value measured in degrees: |
| 83 | + |
| 84 | + .. code-block:: javascript |
| 85 | + |
| 86 | + db.trigonometry.insertOne( |
| 87 | + { |
| 88 | + "_id" : ObjectId( "5c50782193f833234ba90d85" ), |
| 89 | + "angle" : NumberDecimal( "53.1301023541559787031443874490659" ) |
| 90 | + } |
| 91 | + ) |
| 92 | + |
| 93 | + The following aggregation operation uses the |
| 94 | + :expression:`$cosh` expression to calculate the hyperbolic |
| 95 | + cosine of ``angle`` and adds it to the input document using the |
| 96 | + :pipeline:`$addFields` pipeline stage: |
| 97 | + |
| 98 | + .. code-block:: javascript |
| 99 | + |
| 100 | + db.trigonometry.aggregate( [ |
| 101 | + { |
| 102 | + $addFields : { |
| 103 | + "cosh_output" : { $cosh : { $degreesToRadians : "$angle" } } |
| 104 | + } |
| 105 | + } |
| 106 | + ] ) |
| 107 | + |
| 108 | + The :expression:`$degreesToRadians` expression converts the |
| 109 | + ``angle`` in degrees to radians. |
| 110 | + |
| 111 | + Example output: |
| 112 | + |
| 113 | + .. code-block:: javascript |
| 114 | + :copyable: false |
| 115 | + |
| 116 | + { |
| 117 | + "_id" : ObjectId("5c50782193f833234ba90d85"), |
| 118 | + "angle" : NumberDecimal("53.1301023541559787031443874490659"), |
| 119 | + "cosh_output" : NumberDecimal("1.461642741099671277595921778079396") |
| 120 | + } |
| 121 | + |
| 122 | + Because ``angle`` is stored as a :ref:`128-bit decimal |
| 123 | + <shell-type-decimal>`, the :expression:`$cosh` output is also a |
| 124 | + 128-bit decimal. |
| 125 | + |
| 126 | + - id: radians |
| 127 | + name: Hyperbolic Cosine of Value in Radians |
| 128 | + content: | |
| 129 | + |
| 130 | + The following ``trigonometry`` collection contains a document |
| 131 | + that stores an ``angle`` value measured in radians: |
| 132 | + |
| 133 | + .. code-block:: javascript |
| 134 | + |
| 135 | + db.trigonometry.insertOne( |
| 136 | + { |
| 137 | + "_id" : ObjectId( "5c50782193f833234ba90d15" ), |
| 138 | + "angle" : NumberDecimal( "1.6301023541559787031443874490659" ) |
| 139 | + } |
| 140 | + ) |
| 141 | + |
| 142 | + The following aggregation operation uses the |
| 143 | + :expression:`$cosh` expression to calculate the hyperbolic |
| 144 | + cosine of ``angle`` and adds it to the input document using |
| 145 | + the :pipeline:`$addFields` pipeline stage: |
| 146 | + |
| 147 | + .. code-block:: javascript |
| 148 | + |
| 149 | + db.trigonometry.aggregate( [ |
| 150 | + { |
| 151 | + $addFields : { |
| 152 | + "cosh_output" : { $cosh : "$angle" } |
| 153 | + } |
| 154 | + } |
| 155 | + ] ) |
| 156 | + |
| 157 | + Example output: |
| 158 | + |
| 159 | + .. code-block:: javascript |
| 160 | + :copyable: false |
| 161 | + |
| 162 | + { |
| 163 | + "_id" : ObjectId("5c50782193f833234ba90d15"), |
| 164 | + "angle" : NumberDecimal("1.6301023541559787031443874490659"), |
| 165 | + "cosh_output" : NumberDecimal("2.650153334504361016712328539738000") |
| 166 | + } |
| 167 | + |
| 168 | + Because ``angle`` is stored as a :ref:`128-bit decimal |
| 169 | + <shell-type-decimal>`, the :expression:`$cosh` output is also |
| 170 | + a 128-bit decimal. |
0 commit comments