funcool / decimal

An arbitrary-precision Decimal type for ClojureScript
http://funcool.github.io/decimal/latest/
BSD 2-Clause "Simplified" License
13 stars 6 forks source link

Basic math operator aliases #3

Open Necronian opened 7 years ago

Necronian commented 7 years ago

Instead of aliasing / + - * to the equivalent decimal functions can they instead be functions that operate in the same manner as clojure?

I wrote this after looking at clojure.core:

(defn + ([] (decimal 0)) ([x] (decimal x)) ([x y] (plus x y)) ([x y & more] (reduce + (+ x y) more)))

(defn - ([x] (neg x)) ([x y] (minus x y)) ([x y & more] (reduce - (- x y) more)))

(defn / ([x] (div 1 x)) ([x y] (div x y)) ([x y & more] (reduce / (/ x y) more)))

(defn ([] (decimal 1)) ([x] (decimal x)) ([x y] (mul x y)) ([x y & more] (reduce (* x y) more)))

niwinz commented 7 years ago

PR welcome for that!