Ruby Float angle() 方法与示例
浮点角度()是一个浮点类方法,它适用于浮点值,并且对正值和负值的工作方式不同。
Syntax: float.angle()
Parameter: float value which is to be checked
Return: 0 for positive values Otherwise pi(3.141592653589793)
示例 #1:
# Ruby code for angle() method
# Initializing value
a = -100.7 - 10.4
b = -100 * 2000.0
c = (22 + 7.1) * 4
# Printing result
puts "angle value of a : #{a.angle}\n\n"
puts "angle value of b : #{b.angle}\n\n"
puts "angle value of c : #{c.angle}\n\n"
输出 :
angle value of a : 3.141592653589793
angle value of b : 3.141592653589793
angle value of c : 0
示例 #2:
# Ruby code for angle() method
# Initializing value
a = -56.23333333
b = 10000.0
c = -(22 + 7.1)
# Printing result
puts "angle value of a : #{a.angle}\n\n"
puts "angle value of b : #{b.angle}\n\n"
puts "angle value of c : #{c.angle}\n\n"
输出 :
angle value of a : 3.141592653589793
angle value of b : 0
angle value of c : 3.141592653589793