View a markdown version of this page

$atanh - Amazon DocumentDB

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

$atanh

8.0.1 版中的新增内容。

Amazon DocumentDB 中的$atanh运算符返回值的反双曲正切值(双曲弧正切值)。

输入表达式必须解析为介于1(含)范围内的-1数字。超出此范围的值会导致错误。

double默认情况下,返回类型为。如果输入是 128 位十进制,则输出也是 128 位十进制。

参数

  • expression:解析为介于-11之间的数字(含)的表达式。

行为

空值、NaN 和 +/-无穷大

示例 结果
{ $atanh: NaN } NaN
{ $atanh: null } null
{ $atanh: 1 } Infinity
{ $atanh: -1 } -Infinity
{ $atanh: Infinity }{ $atanh: -Infinity } 引发错误。

当输入为null或引用字段缺失时,结果为nullNaN农产品的输入NaN。边界值1-Infinity分别-1生成Infinity和。超出[-1, 1]范围(包括±Infinity)的任何值都会导致错误。

示例(MongoDB Shell)

以下示例显示如何使用$atanh运算符计算值的反双曲正切值。

创建示例文档

db.values.insertMany([ { "_id": 1, "value": 0 }, { "_id": 2, "value": 0.5 }, { "_id": 3, "value": -0.5 } ]);

查询示例

db.values.aggregate([ { $project: { "result": { $atanh: "$value" } }} ]);

输出

[ { "_id": 1, "result": 0 }, { "_id": 2, "result": 0.5493061443340548 }, { "_id": 3, "result": -0.5493061443340548 } ]

代码示例

要查看使用$atanh运算符的代码示例,请选择要使用的语言的选项卡:

Node.js
const { MongoClient } = require('mongodb'); async function main() { const client = await MongoClient.connect('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false'); const db = client.db('test'); const collection = db.collection('values'); const result = await collection.aggregate([ { $project: { "result": { $atanh: "$value" } }} ]).toArray(); console.log(result); await client.close(); } main();
Python
from pymongo import MongoClient def main(): client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false') db = client['test'] collection = db['values'] result = list(collection.aggregate([ { '$project': { 'result': { '$atanh': '$value' } }} ])) print(result) client.close() if __name__ == "__main__": main()