Details

Type: Enhancement

Status: Open

Priority: Major

Resolution: Unresolved

Affects Version/s: Release 1.6

Fix Version/s: None

Component/s: None

Labels:None

Approval:Triaged
Description
Because ratio values reduce to lowest terms and, for integral values where the lowest term is N/1, are autoconverted to BigInts (and formerly Longs), the current behavior of clojure.core/numerator and clojure.core/denominator yield unexpected results.
user=> (numerator 1/3) 1 user=> (numerator (+ 1/3 2/3)) ClassCastException clojure.lang.BigInt cannot be cast to clojure.lang.Ratio clojure.core/numerator (core.clj:3306) user=> (denominator 1/3) 3 user=> (denominator (+ 1/3 2/3)) ClassCastException clojure.lang.BigInt cannot be cast to clojure.lang.Ratio clojure.core/denominator (core.clj:3314) user=>
The autoconversion to Longs is not really the problem in my mind. I'd like to see numerator return the original value when presented with a BigInt and denominator always return 1 when presented with a BigInt. It seems reasonable to request the same for Longs.
If desired, I'd be happy to produce a patch.
I don't know the official stance on this ticket, but will add some notes.
Aaron, numerator and denominator are pretty clearly documented to work on Ratio types only.
It is pretty easy to write mynumerator and mydenominator that work exactly as you wish, checking for the type of arg and using numerator, denominator for Ratio types, and doing whatever you think is correct for other numeric types.