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


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


asin()是Ruby中的內置函數,返回數字的反正弦值,表示對該函數賦予正弦值,它將以弧度返回對應於該值的角度。傳遞的值介於-1和+1之間。

用法:Math.sin(value) 

參數:該函數接受一個強製性參數值,我們必須找到其對應角度。


返回值:它返回以弧度為單位的角度,範圍為-pi /2到+ pi /2。

例子1

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

輸出

1.5707963267948966
0.5235987755982989
-1.5707963267948966
-1.1197695149986342

例子2

#Ruby program for asin() function 
  
#Assigning values 
val1 = 0.87 val2 = 0.67 val3 = -0.679 val4 = -0.564 
  
#Prints the asin() value 
                                              puts Math.asin(val1) 
                                                  puts Math.asin(val2) 
                                                      puts Math.asin(val3) 
                                                          puts Math.asin(val4)

輸出

1.0552023205488061
0.7342087874533589
-0.746399633896421
-0.59922176813665

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



相關用法


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