红宝石 |数字角度()函数
angle()是 Ruby 中的内置方法,如果数字为正,则返回 0,否则返回等于 pi 的浮点值。
Syntax: num.angle()
Parameters: The function needs a number.
Return Value: It returns 0 if the number is positive, else it returns a float value which is equal to pi. .
示例 1 :
Ruby
# Ruby program for angle() method in Numeric
# Initialize a number
num = -19
# Prints angle() of num
puts num.angle()
Ruby
# Ruby program for angle() method in Numeric
# Initialize a number
num = 100
# Prints angle() of num
puts num.angle()
输出:
3.141592653589793
示例 2 :
红宝石
# Ruby program for angle() method in Numeric
# Initialize a number
num = 100
# Prints angle() of num
puts num.angle()
输出:
0