Para agentes de IA: um índice de documentação está disponível em https://www.mongodb.com/pt-br/docs/llms.txt — as versões de markdown de todas as páginas estão disponíveis anexando .md a qualquer caminho de URL.
Menu Docs

$tanh (operador de expressão )

$tanh

Retorna a tangente hiperbólica de um valor medido em radianos.

$tanh tem a seguinte sintaxe:

{ $tanh: <expression> }

$tanh 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.

By default $tanh returns values as a double. $tanh can 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.

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.

Exemplo
Resultados

{ $tanh: NaN }

NaN

{ $tanh: null }

null

{ $tanh: -Infinity }

-1

{ $tanh: Infinity }

1

A seguinte collection do trigonometry contém um documento que armazena um valor do angle medido em graus:

db.trigonometry.insertOne(
{
"_id" : ObjectId( "5c50782193f833234ba90d45" ),
"angle" : Decimal128( "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" } }
}
}
] )

A expressão $degreesToRadians converte o angle de graus para radianos.

Saída de exemplo:

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

Because angle is stored as a 128-bit decimal, the $tanh output is also a 128-bit decimal.

Avalie esta página