Open In App

Ruby | Numeric phase() function

Improve
Improve
Like Article
Like
Save
Share
Report

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

Last Updated : 19 Mar, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads