當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Ruby Math atanh()用法及代碼示例


atanh()是Ruby中的內置函數,返回以弧度給出的角度的反雙曲正切值。它接受[-1,+1]範圍內的值,並返回[-INFINITY,INFINITY]範圍內的值。

用法:Math.atanh(value) 

參數:該函數接受一個強製性參數值,該值指定弧度的反雙曲角在[-1,1]範圍內。


返回值:返回以弧度表示的角度的雙曲線反正切值

例子1

#Ruby program for atanh() function 
  
#Assigning values 
val1 = -1 val2 = 1 val3 = -0.5 val4 = 0.7 
  
#Prints the atanh() value 
                                      puts Math.atanh(val1) 
                                          puts Math.atanh(val2) 
                                              puts Math.atanh(val3) 
                                                  puts Math.atanh(val4)

輸出

 -Infinity
Infinity
-0.5493061443340548
0.8673005276940531

例子2

#Ruby program for atanh() function 
  
#Assigning values 
val1 = -0.7 val2 = 0.6 val3 = -0.56 val4 = 0.90 
  
#Prints the atanh() value 
                                           puts Math.atanh(val1) 
                                               puts Math.atanh(val2) 
                                                   puts Math.atanh(val3) 
                                                       puts Math.atanh(val4)

輸出

-0.8673005276940531
0.6931471805599453
-0.632833186665638
1.4722194895832204

參考:https://devdocs.io/ruby~2.5/math#method-c-atanh



相關用法


注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Ruby | Math atanh() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。