Open In App

Ruby | Numeric phase() function

The phase() is an inbuilt method in Ruby returns 0 if the value is positive, else it returns a float value 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.



Example 1:




# Ruby program for phase()
# method in Numeric
  
# Initialize a number 
num1 = 10
  
# Prints the phase
puts num1.phase()

Output:

0

Example 2:




# Ruby program for phase()
# method in Numeric
  
# Initialize a number 
num1 = -10
  
# Prints the phase
puts num1.phase()

Output:

3.141592653589793
Article Tags :