From: Patrick Houk <path...@gmail.com>
Date: Fri, 5 Oct 2012 07:42:44 -0700 (PDT)
Local: Fri, Oct 5 2012 10:42 am
Subject: Re: == is not transitive?
I was bitten by this a year ago and posted here:
http://groups.google.com/group/clojure/browse_frm/thread/9091ad790fc9... My workaround is to call BigDecimal#stripTrailingZeros before passing
user> (== 1 (.stripTrailingZeros 1.0M))
However, there is an edge case:
user> (== 0 (.stripTrailingZeros 0.0M))
Which is due to this Java bug:
So I use a function like the following instead of bigdec to parse
(defn parse-stripped-bigdec [^String value-str]
Be aware that stripping the zeros changes how the BigDecimal is
user> (str (parse-stripped-bigdec "10"))
So, I have a special case for BigDecimal that calls #toPlainString in
user> (.toPlainString (parse-stripped-bigdec "10"))
I hope that helps.
On Oct 4, 8:39 pm, Ben Wolfson <wolf...@gmail.com> wrote:
> user> [(== 0 0.0) (== 0.0 0.0M) (== 0.0M 0)]
> [true true false] > user> [(== 0 0.0 0.0M) (== 0 0.0M 0.0) (== 0.0 0 0.0M) (== 0.0 0.0M 0) > (== 0.0M 0.0 0) (== 0.0M 0 0.0)] > [true false false false true false] > --
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||