Sha256: d2714adc6f84a5180092227ee6ab9325ee5e5989d6fdc0b60821af9bd0c0afb6
Contents?: true
Size: 503 Bytes
Versions: 123
Compression:
Stored size: 503 Bytes
Contents
(ns complex-numbers) (defn real [[a _]] a) (defn imaginary [[_ b]] b) (defn abs [[a b]] (Math/sqrt (apply + (map #(Math/pow % 2) [a b])))) (defn conjugate [[a b]] [a (- b)]) (defn add [[a b] [c d]] [(+ a c) (+ b d)]) (defn sub [[a b] [c d]] [(- a c) (- b d)]) (defn mul [[a b] [c d]] [(- (* a c) (* b d)) (+ (* a d) (* b c))]) (defn div [[a b] [c d]] (let [denominator (apply + (map #(Math/pow % 2) [c d]))] [(/ (+ (* a c) (* b d)) denominator) (/ (- (* b c) (* a d)) denominator)]))
Version data entries
123 entries across 123 versions & 1 rubygems