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


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


cos()是Ruby中的內置函數,返回以弧度表示的給定角度的正弦值,其範圍為[-inf,+ inf]。返回的值在[-1,+1]範圍內。

用法:Math.cos(value) 

參數:該函數接受一個強製性參數值,其返回相應的正弦值。


返回值:返回正弦。

例子1

#Ruby program for sin() function 
  
#Assigning values 
val1 = 176 val2 = Math::PI / 2 val3 = -3123 val4 = -89 
  
#Prints the sin() value 
                                                    puts Math.sin(val1) 
                                                        puts Math.sin(val2) 
                                                            puts Math.sin(val3) 
                                                                puts Math.sin(val4)

輸出

 0.07075223608034517
1.0
-0.25408576770942626
-0.8600694058124533

例子2

#Ruby program for sin() function 
  
#Assigning values 
val1 = 1 val2 = 0 val3 = 989 val4 = -8932 
  
#Prints the sin() value 
                                     puts Math.sin(val1) 
                                         puts Math.sin(val2) 
                                             puts Math.sin(val3) 
                                                 puts Math.sin(val4)

輸出

0.8414709848078965
0.0
0.5660330877786267
0.43684277891924755

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



相關用法


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