Horje
Ruby | Numeric imag() function

The imag() is an inbuilt method in Ruby returns the imag part of the given number.

Syntax: num.imag()

Parameters: The function needs a number whose imag part is to be returned.

Return Value: It returns the imag part.

Example 1:




# Ruby program for imag()
# method in Numeric
  
# Initialize a number 
num1 = Complex(10, 9)
  
# Prints Imaginary number
puts num1.imag()

Output:

9

Example 2:




# Ruby program for imag()
# method in Numeric
  
# Initialize a number 
num1 = Complex(10, 0)
  
# Prints Imaginary number
puts num1.imag()

Output:

0



Reffered: https://www.geeksforgeeks.org


Ruby

Related
Ruby | Date <=>() method Ruby | Date <=>() method
Ruby | Time utc function Ruby | Time utc function
Ruby | Time - function Ruby | Time - function
Ruby | Date ajd() method Ruby | Date ajd() method
Ruby | Time to_date() function Ruby | Time to_date() function

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
9