红宝石 |数值 i()函数
i()是 Ruby 中的一个内置方法,它返回一个带有给定虚部的复数。
Syntax: num.i()
Parameters: The function needs a number which is the imaginary part of the complex number.
Return Value: It returns a complex number with the imaginary part.
示例 1 :
# Ruby program for i()
# method in Numeric
# Initialize a number
num1 = -10
# Prints Complex number
puts num1.i()
输出:
0-10i
示例 2 :
# Ruby program for i()
# method in Numeric
# Initialize a number
num1 = 12
# Prints Complex number
puts num1.i()
输出:
0+12i