当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。