📜  红宝石 |数学 cos()函数

📅  最后修改于: 2022-05-13 01:54:45.997000             🧑  作者: Mango

红宝石 |数学 cos()函数

cos()是 Ruby 中的一个内置函数,返回以弧度表示的给定角度的余弦值,该角度在[-inf, +inf]范围内。返回值在[-1, +1] 范围内。

示例 1

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

输出

0.5403023058681398
0.8775825618903728
0.5403023058681398
0.6216099682706644

示例 2

#Ruby program for cos() function
  
#Assigning values
val1 = 109 val2 = 133 val3 = -13243 val4 = -9898
  
#Prints the cos() value
                                            puts Math.cos(val1)
                                                puts Math.cos(val2)
                                                    puts Math.cos(val3)
                                                        puts Math.cos(val4)

输出

-0.577002178942952
0.4948722204034305
-0.37447564566939956
-0.40075875500376773

参考:https://devdocs.io/ruby~2.5/math#method-c-cos