Implement abs, round for additional number types (patch attached)


clojure.algo.generic.math-functions/abs did not work on:
I defined defmethods for these classes, plus one for java.lang.Number to preserve the previous functionality for other number classes.

clojure.algo.generic.math-functions/round did not work on
the various java integer classes (why shouldn't round work on integers?)
I defined defmethods to delegate java.Math.round for double and float, to act as the identity on the various integer classes, to delegate to java.math.BigDecimal#round for BigDecimal, and to cast Ratio to either a double or a BigDecimal and round it.


clojure.algo.generic 0.1.2, java 1.8


Cort Spellman
August 31, 2015, 6:31 AM

New patch (off of master, NOT off of the first patch). I'm seeing the tests pass under Clojure 1.2 - 1.7.
Tests fail for 1.1 - the error says clojure.core/spit is not defined.

I conditionally made the defmethods for BigInt by using java.lang.Class/forName to check whether BigInt exists. I used eval for the abs defmethod; round didn't need it.

I don't know if this is idiomatic and I'd welcome an improvement
I tried a combination of java.lang.Class/forName and .getMethod but couldn't get it working.

Hope this helps!

Cort Spellman
August 30, 2015, 10:32 PM

I get passing tests under Clojure 1.2 when I comment out the BigInt stuff.

I tried

  • conditionally making defmethods for BigInt based on the Clojure minor version

  • putting the defmethods for BigInt inside of a try

In either case I get a ClassNotFoundException.

How would y'all do this?

Cort Spellman
August 28, 2015, 5:40 AM

Looks like BigInt was introduced in Clojure 1.3:

What do y'all think the good approach is?

Sean Corfield
August 28, 2015, 12:56 AM

Looks like the patch is not compatible with Clojure 1.2:

Several Contrib projects are dropping support for 1.2 now so that's a reasonable choice if you don't want to modify the code.

Sean Corfield
August 27, 2015, 7:49 AM

I've reminded Cort that he needs to get a signed CA on file for the patch to be used.


Konrad Hinsen


Cort Spellman