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

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

红宝石 |数学 sin()函数

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

示例 1

Ruby
#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)


Ruby
#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.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