Ruby Float phase()方法及示例
float phase() 是一个float类的方法,它对float值起作用,对正值和负值的作用不同。
语法: float.phase()
参数: 要检查的浮点数值
返回: 正值返回0,否则返回pi(3.141592653589793)
例子 #1 :
# Ruby code for phase() method
# Initializing value
a = -100.7 - 10.4
b = -100 * 2000.0
c = (22 + 7.1) * 4
# Printing result
puts "phase value of a : #{a.phase}\n\n"
puts "phase value of b : #{b.phase}\n\n"
puts "phase value of c : #{c.phase}\n\n"
输出:
phase value of a : 3.141592653589793
phase value of b : 3.141592653589793
phase value of c : 0
例子#2 。
# Ruby code for phase() method
# Initializing value
a = -56.23333333
b = 10000.0
c = -(22 + 7.1)
# Printing result
puts "phase value of a : #{a.phase}\n\n"
puts "phase value of b : #{b.phase}\n\n"
puts "phase value of c : #{c.phase}\n\n"
输出:
phase value of a : 3.141592653589793
phase value of b : 0
phase value of c : 3.141592653589793