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 <alanmichaelforres...@googlemail.com> wrote: > 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 example, > > (.add (Complex. 1.0 2.0) 2) > > produces an IllegalArgumentException. The method only works if at > least one of the arguments is a complex number although the other can > be a double. > > What would be the best way of handling this? Should I just wrap add > the way it is and explain what types are expected in the > documentation, or is there a better way of dealing with this issue > that would allow Clojure number types to be used seamlessly? > > Alan > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.