📜  红宝石 |复杂的**函数

📅  最后修改于: 2022-05-13 01:54:19.568000             🧑  作者: Mango

红宝石 |复杂的**函数

Complex#**()是一个 Complex 类方法,它返回一个复数值的幂值。

示例 #1:

Ruby
# Ruby code for Complex.**() method
 
# declaring Complex value
a = Complex(200)
 
# declaring Complex value
b = Complex(-1, 4)
 
# declaring Complex value
c = Complex('i')
 
 
# exponentiation
puts "Complex ** form : #{a**b}\n\n"
 
puts "Complex ** form : #{b**c}\n\n"
 
puts "Complex ** form : #{c**a}\n\n"


Ruby
# Ruby code for Complex.**() method
 
# declaring Complex value
a = Complex(20, 90)
 
# declaring Complex value
b = Complex('i')
 
# declaring Complex value
c = Complex(100, -500)
 
 
# exponentiation
puts "Complex ** form : #{a**b}\n\n"
 
puts "Complex ** form : #{b**c}\n\n"
 
puts "Complex ** form : #{c**a}\n\n"


输出 :

Complex ** form : -0.003491132876870155+0.0035793841978804587i

Complex ** form : 0.02498917737380923+0.16078139726660404i

Complex ** form : 1+0i

示例 #2:

红宝石

# Ruby code for Complex.**() method
 
# declaring Complex value
a = Complex(20, 90)
 
# declaring Complex value
b = Complex('i')
 
# declaring Complex value
c = Complex(100, -500)
 
 
# exponentiation
puts "Complex ** form : #{a**b}\n\n"
 
puts "Complex ** form : #{b**c}\n\n"
 
puts "Complex ** form : #{c**a}\n\n"

输出 :

Complex ** form : -0.048469153281543935-0.2541080831409528i

Complex ** form : Infinity+Infinity*i

Complex ** form : 6.077051204650672e+107-3.0041002556732734e+107i