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