Docs Menu

$tanh (aggregation)

項目一覧

$tanh

ラジアンで測定された値の双曲線タンジェントを返します。

$tanhの構文は次のとおりです。

{ $tanh: <expression> }

$tanhは、ラジアンで測定された数値に変換される有効なであればどれでもかまいません。 式が値を度単位で返す場合は、 $degreesToRadians演算子を使用して値をラジアンに変換します。

デフォルトでは、 $tanhは値をdoubleとして返します。 $tanhでは、 <expression>が128ビットの 10 進数値に解決される場合は、 128ビットの 10 進数として値を返すこともできます。

式の詳細については、「式演算子」を参照してください。

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

結果

{ $tanh: NaN }

NaN

{ $tanh: null }

null

{ $tanh: -Infinity }

-1

{ $tanh: Infinity }

1

次のtrigonometryコレクションには、度単位で測定されたangle値を保存するドキュメントが含まれています。

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

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

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

$degreesToRadians式は、 angleを度単位でラジアンに変換します。

出力例:

{
"_id" : ObjectId("5c50782193f833234ba90d45"),
"angle" : NumberDecimal("53.1301023541559787031443874490659"),
"tanh_output" : NumberDecimal("0.7293303448445332820512777329448416")
}

angle128ビットの 10 進数として保存されるため、 $tanhの出力も128ビットの 10 進数になります。

次のtrigonometryコレクションには、ラジアンで測定されたangle値を保存するドキュメントが含まれています。

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

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

db.trigonometry.aggregate( [
{
$addFields : {
"tanh_output" : { $tanh : "$angle" }
}
}
] )

出力例:

{
"_id" : ObjectId("5c50782193f833234ba90d55"),
"angle" : NumberDecimal("1.6301023541559787031443874490659"),
"tanh_output" : NumberDecimal("0.9260761562750713360156803177935379")
}

angle128ビットの 10 進数として保存されるため、 $tanhの出力も128ビットの 10 進数になります。

項目一覧