Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Arithmetic-Complex/Ruby/arithmetic-complex-1.rb
Normal file
14
Task/Arithmetic-Complex/Ruby/arithmetic-complex-1.rb
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# Four ways to write complex numbers:
|
||||
a = Complex(1, 1) # 1. call Kernel#Complex
|
||||
i = Complex::I # 2. use Complex::I
|
||||
b = 3.14159 + 1.25 * i
|
||||
c = '1/2+3/4i'.to_c # 3. Use the .to_c method from String, result ((1/2)+(3/4)*i)
|
||||
c = 1.0/2+3/4i # (0.5-(3/4)*i)
|
||||
|
||||
# Operations:
|
||||
puts a + b # addition
|
||||
puts a * b # multiplication
|
||||
puts -a # negation
|
||||
puts 1.quo a # multiplicative inverse
|
||||
puts a.conjugate # complex conjugate
|
||||
puts a.conj # alias for complex conjugate
|
||||
4
Task/Arithmetic-Complex/Ruby/arithmetic-complex-2.rb
Normal file
4
Task/Arithmetic-Complex/Ruby/arithmetic-complex-2.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# Other ways to find the multiplicative inverse:
|
||||
puts 1.quo a # always works
|
||||
puts 1.0 / a # works, but forces floating-point math
|
||||
puts 1 / a # might truncate to integer
|
||||
Loading…
Add table
Add a link
Reference in a new issue