arithmetic_complex.sf 563 B

1234567891011121314151617181920
  1. #!/usr/bin/ruby
  2. #
  3. ## https://rosettacode.org/wiki/Arithmetic/Complex
  4. #
  5. var a = 1:1; # Complex(1, 1)
  6. var b = 3.14159:1.25; # Complex(3.14159, 1.25)
  7.  
  8. [ a + b, # addition
  9. a * b, # multiplication
  10. -a, # negation
  11. a.inv, # multiplicative inverse
  12. a.conj, # complex conjugate
  13. a.abs, # abs
  14. a.sqrt, # sqrt
  15. b.re, # real
  16. b.im, # imaginary
  17. ].each { |c| say c };