文档菜单
文档首页
/
MongoDB 手册
/ / /

$atanh(聚合)

本页内容

  • 行为
  • 示例
$atanh

返回一个值的反双曲正切(双曲反正切)。

$atanh 的语法如下

{ $atanh: <expression> }

$atanh 任何有效的表达式,该表达式解析为介于 -11 之间的数字,例如 -1 <= value <= 1

$atanh 返回弧度值。使用 $radiansToDegrees 操作符将输出值从弧度转换为度。

默认情况下,$atanh 返回 double 类型的值。只要 <expression> 解析为 128 位十进制值,$atanh 也可以返回 128 位十进制值。

有关表达式的更多信息,请参阅 表达式运算符。

如果参数解析为 null 或引用一个缺失的字段,$atanh 返回 null。如果参数解析为 NaN$atanh 返回 NaN。如果参数解析为负或正无穷大,$atanh 抛出错误。如果参数解析为 +1-1$atanh 分别返回 Infinity-Infinity

示例
结果
{ $atanh: NaN }
NaN
{ $atanh: null }
null
{ $atanh: 1 }
Infinity
{ $atanh: -1}
-Infinity

{ $atanh : Infinity}

{ $atanh : -Infinity }

抛出类似于以下格式的错误消息

"errmsg" :
"Failed to optimize pipeline :: caused by :: cannot
apply $atanh to -inf, value must in (-inf,inf)"

trigonometry 集合包含一个文档,该文档存储一个二维图形 x 轴上的值

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"x-coordinate" : NumberDecimal("0.5")
}

以下聚合操作使用 $atanh 表达式来计算 x 坐标的双曲反正切,并使用 $addFields 管道阶段将其添加到输入文档中。

db.trigonometry.aggregate([
{
$addFields : {
"y-coordinate" : {
$radiansToDegrees : { $atanh : "$x-coordinate" }
}
}
}
])

表达式 $radiansToDegrees 将由 $atanh 返回的弧度值转换为等价的度数。

命令返回以下输出

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"x-coordinate" : NumberDecimal("0.5"),
"y-coordinate" : NumberDecimal("31.47292373094538001977241539068589")
}

由于 x-坐标 被存储为 128位十进制,因此 $atanh 的输出是128位十进制。

trigonometry 集合包含一个文档,该文档存储一个二维图形 x 轴上的值

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"x-coordinate" : NumberDecimal("0.5")
}

以下聚合操作使用 $atanh 表达式来计算 x 坐标的双曲反正切,并使用 $addFields 管道阶段将其添加到输入文档中。

db.trigonometry.aggregate([
{
$addFields : {
"y-coordinate" : {
$atanh : "$x-coordinate"
}
}
}
])

命令返回以下输出

{
"_id" : ObjectId("5c50782193f833234ba90d85"),
"x-coordinate" : NumberDecimal("0.5"),
"y-coordinate" : NumberDecimal("0.5493061443340548456976226184612628")
}

由于 x-坐标 被存储为 128位十进制,因此 $asin 的输出是128位十进制。

返回

$atan2

本页内容