$atanh (aggregation)

    在本页面

    $asinh

    4.2版中的新功能。

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

    $atanh具有以下语法:

    1. { $atanh: <expression> }

    $atanh接受任何有效的表达式,该表达式可解析为-1 和之间的数字1,例如。-1 <= value <= 1

    $atanh返回以弧度为单位的值。使用 $radiansToDegrees运算符将输出值从弧度转换为度。

    默认情况下以形式$atanh返回值double$atanh也可以返回值作为 128-bit小数 ,只要该<expression>解析为一个128-bit的十进制值。

    有关表达式的更多信息,请参见 表达式。

    行为

    nullNaN+/- Infinity

    如果参数解析为的值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}
    or
    { $atanh : -Infinity }
    引发类似于以下格式化输出的错误消息:
    “errmsg” : “Failed to optimize pipeline :: caused by :: cannot apply $atanh to -inf, value must in (-inf,inf)”

    例子

    度数的反双曲正切值

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

    1. {
    2. "_id" : ObjectId("5c50782193f833234ba90d85"),
    3. "x-coordinate" : NumberDecimal("0.5")
    4. }

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

    1. db.trigonometry.aggregate([
    2. {
    3. $addFields : {
    4. "y-coordinate" : {
    5. $radiansToDegrees : { $atanh : "$x-coordinate" }
    6. }
    7. }
    8. }
    9. ])

    $radiansToDegrees表达式将返回的弧度值转换为$atanh以度为单位的等效值。

    该命令返回以下输出:

    1. {
    2. "_id" : ObjectId("5c50782193f833234ba90d85"),
    3. "x-coordinate" : NumberDecimal("0.5"),
    4. "y-coordinate" : NumberDecimal("31.47292373094538001977241539068589")
    5. }

    由于x-coordinate存储为 128-bit十进制数,因此输出 $atanh为128-bit十进制数。

    弧度的反双曲正切值

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

    1. {
    2. "_id" : ObjectId("5c50782193f833234ba90d85"),
    3. "x-coordinate" : NumberDecimal("0.5")
    4. }

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

    1. db.trigonometry.aggregate([
    2. {
    3. $addFields : {
    4. "y-coordinate" : {
    5. $atanh : "$x-coordinate"
    6. }
    7. }
    8. }
    9. ])

    该命令返回以下输出:

    1. {
    2. "_id" : ObjectId("5c50782193f833234ba90d85"),
    3. "x-coordinate" : NumberDecimal("0.5"),
    4. "y-coordinate" : NumberDecimal("0.5493061443340548456976226184612628")
    5. }

    由于x-coordinate存储为 128-bit十进制数,因此输出 $asin为128-bit十进制数。

    译者:李冠飞

    校对: