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


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