You are viewing a single comment's thread from:

RE: Complex numbers in clojure

in Proof of Brain4 years ago

I find it strange that there is no decimal number class in Boost for C++. C# has a special decimal type built-in. I mention this because I think there is a greater need for that kind of stuff than complex numbers. The ability to save monetary amounts with no internal repeating decimals.

Python has both complex numbers builtin and a Decimal numbers module.


Posted via proofofbrain.io

Sort:  

I haven't used the Boost libraries at all, been out of the C++ ecosystem for a while now.

Complex numbers are super useful for physics stuff and also for optimisation. I just implemented it as a practice exercise, would be really surprised if there isn't a library for complex numbers already existing in Clojure.

One really cool feature in Clojure is the symbolic representation of rational numbers:

(/ 1 3)

evaluates to 1/3 rather than 0.3333. This allows more precise calculations, as rounding only needs to be done at the end.

Posted Using LeoFinance Beta

Oh wow. If you write 0.20, it will be a repeated decimal in Clojure, won't it? So instead you could handle 0.2 by writing (/ 1 5).

Yes exactly. 0.2 would be of type double and 1/5 is called "ratio" type in Clojure.

Posted Using LeoFinance Beta