1234567891011121314151617181920 |
- #!/usr/bin/ruby
- #
- ## https://rosettacode.org/wiki/Arithmetic/Complex
- #
- var a = 1:1; # Complex(1, 1)
- var b = 3.14159:1.25; # Complex(3.14159, 1.25)
-
- [ a + b, # addition
- a * b, # multiplication
- -a, # negation
- a.inv, # multiplicative inverse
- a.conj, # complex conjugate
- a.abs, # abs
- a.sqrt, # sqrt
- b.re, # real
- b.im, # imaginary
- ].each { |c| say c };
|