红宝石 |数值 arg()函数
arg()是 Ruby 中的一个内置方法,如果数字为正,则返回 0,否则返回等于 pi 的浮点值。
Syntax: num.arg()
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 arg() method in Numeric
# Initialize a number
num = -19
# Prints arg() of num
puts num.arg()
Ruby
# Ruby program for arg() method in Numeric
# Initialize a number
num = 100
# Prints arg() of num
puts num.arg()
输出:
3.141592653589793
示例 2 :
红宝石
# Ruby program for arg() method in Numeric
# Initialize a number
num = 100
# Prints arg() of num
puts num.arg()
输出:
0