Open In App

Ruby Float phase() method with example

Last Updated : 07 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Float phase() is a float class method which works on float values and works differently for both positive and negative values.

Syntax: float.phase()

Parameter: float value which is to be checked

Return: return 0 for positive values otherwise return pi(3.141592653589793)

Example #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"


Output :

phase value of a : 3.141592653589793

phase value of b : 3.141592653589793

phase value of c : 0

Example #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"


Output :

phase value of a : 3.141592653589793

phase value of b : 0

phase value of c : 3.141592653589793

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads