Reported by tomfaulhaber, Dec 28, 2008
The clojure.core/bigdec function truncates rationals to ints:
(bigdec 1/2) => 0M
As opposed to:
(bigdec 0.5) => 0.5M
This happens because rationals fall into the number? case in bigdec which
converts the rational to a long before converting to BigDecimal.
I'm not sure that this behavior is completely wrong (since there's no way
to specify the behavior of 1/3 in the current API, for instance), but we
should probably at least document it.
Comment 1 by jbondeson, Jan 30, 2009
I discussed this along with another issue here:
(bigdec (/ 1 3)) should probably behave exactly like (/ 1M 3) which throws an
ArithmeticException unless you are inside a "with-precision" block.
I have attached a rather simple fix for this to have Ratio -> BigDecimal conversion
behave like this.
521 bytes Download
Comment 2 by richhickey, Feb 09, 2009
fixed in svn 1257 - thanks!