

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# $atanh
<a name="atanh"></a>

8.0.1 版的新功能。

Amazon DocumentDB 中的`$atanh`運算子會傳回值的反雙曲正切 （雙曲電弧正切）。

輸入表達式必須解析為 `-1``1`（包含） 範圍內的數字。超出此範圍的值會導致錯誤。

傳回類型預設為 `double` 。如果輸入是 128 位元的小數位數，則輸出也是 128 位元的小數位數。

**參數**
+ `expression`：解析為介於 `-1`和 之間的數字的表達式`1`，包含 。

## Behavior (行為)
<a name="atanh-behavior"></a>

**null、NaN 和 \+/- Infinity**


| 範例 | 結果 | 
| --- | --- | 
| { $atanh: NaN } | NaN | 
| { $atanh: null } | null | 
| { $atanh: 1 } | Infinity | 
| { $atanh: -1 } | -Infinity | 
| { $atanh: Infinity } 或 { $atanh: -Infinity } | 擲回錯誤。 | 

當輸入為 `null`或參考欄位遺失時，結果為 `null`。的輸入`NaN`會產生 `NaN`。邊界值 `1`和 `-Infinity`分別`-1`產生 `Infinity`和 。超出`[-1, 1]`範圍 （包括 `±Infinity`) 的任何值都會導致錯誤。

## 範例 (MongoDB Shell)
<a name="atanh-examples"></a>

下列範例顯示如何使用 `$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 }
]
```

## 程式碼範例
<a name="atanh-code"></a>

若要檢視使用 `$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()
```

------