红宝石 |数字 imag()函数
imag()是 Ruby 中的一个内置方法,它返回给定数字的 imag 部分。
Syntax: num.imag()
Parameters: The function needs a number whose imag part is to be returned.
Return Value: It returns the imag part.
示例 1 :
# Ruby program for imag()
# method in Numeric
# Initialize a number
num1 = Complex(10, 9)
# Prints Imaginary number
puts num1.imag()
输出:
9
示例 2 :
# Ruby program for imag()
# method in Numeric
# Initialize a number
num1 = Complex(10, 0)
# Prints Imaginary number
puts num1.imag()
输出:
0