📜  红宝石 |数学 tanh()函数

📅  最后修改于: 2022-05-13 01:55:25.363000             🧑  作者: Mango

红宝石 |数学 tanh()函数

tanh()是 Ruby 中的内置函数,返回以弧度给出的值的双曲正切值。传递的值在[-inf, +inf]范围内。返回值在[-1, +1]范围内。

示例 1

#Ruby program for tanh() function
  
#Assigning values
val1 = -1023 val2 = 0.67 val3 = 98 val4 = -39
  
#Prints the tanh() value
                                           puts Math.tanh(val1)
                                               puts Math.tanh(val2)
                                                   puts Math.tanh(val3)
                                                       puts Math.tanh(val4)

输出

-1.0
0.5849798828807289
1.0
-1.0

示例 2

#Ruby program for tanh() function
  
#Assigning values
val1 = 0 val2 = 100 val3 = -98 val4 = -6
  
#Prints the tanh() value
                                       puts Math.tanh(val1)
                                           puts Math.tanh(val2)
                                               puts Math.tanh(val3)
                                                   puts Math.tanh(val4)

输出

0.0
1.0
-1.0
-0.9999877116507956

参考:https://devdocs.io/ruby~2.5/math#method-c-tanh