Re: Wrapping org.apache.commons.math3.complex

2015-05-04 Thread Mikera
You often have to do bit of manual coercion to make things work nicely with the whole set of possible Clojure numerical types. Fortunately there are plenty of built-in functions in clojure.core to help you do this. In your specific case I would do: (.add (Complex. 1.0 2.0) (double 2)) This

Wrapping org.apache.commons.math3.complex

2015-05-02 Thread Alan Forrester
Hello I'm currently trying to wrap org.apache.commons.math3.complex http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/complex/Complex.html to make a complex number library and I have a problem. Many of the methods won't work with all Clojure number types. For

Re: Wrapping org.apache.commons.math3.complex

2015-05-02 Thread PlĂ­nio Balduino
Hi Alan Excuse me if I didn't understand your question, but I think a type hint would solve. Maybe you could abstract this for the final user in Clojure. (.add (Complex. 1.0 2.0) ^double 2) On Sat, May 2, 2015 at 8:53 AM, Alan Forrester alanmichaelforres...@googlemail.com wrote: Hello I'm

Re: Wrapping org.apache.commons.math3.complex

2015-05-02 Thread James Reeves
You could just convert any Number into a Double: (if (number? x) (double x) x) Or create a protocol for the conversion. If you're concerned about performance, measure the result with a benchmarking library like Criterium. - James On 2 May 2015 at 12:53, Alan Forrester