On 17.01.2010, at 23:13, Jevgeni Holodkov wrote:

decimal. Entered 0.1 is actually a very precise number and the fact
that it gets imprecise somewhere internally should now affect, IMHO,
the result of multiplying two very precise numbers. What's the point

There is no such thing as a "precise" or "imprecise" number as far as the computer is concerned. What differs is the interpretation that humans (programmers and users) make of the data items. The rules of floating-point arithmetic (in Clojure and pretty much anywhere else) are designed with the expectation that floats will be interpreted as approximations. So as soon as you use a single float in some expression, the whole expression becomes something to be considered approximate, and therefore it will be of float type.

Unlike most languages, Clojure has a way to express precise non- integer numbers: ratios. Just use 11/10 instead of 1.1 (or (+ 1 1/10) if you prefer), and you won't see any floating-point result. In fact, what you are complaining about is simply that the input string 1.1 is interpreted as a float rather than as a ratio. Obviously it can't mean both, so some choice has to be made.

If is this is never to be fixed by some reason (which one can it be?),
then let me ask another question. I wonder, if there is a requirement
for user to write custom business rules himself (lets say he wants to
increase the price on 10%) and he uses 1.1, can I solve this issue
with Clojure core without using external parsers/preprocessors?
Something like replacing the 1.1 with 1.1M or 11/10 before evaluating
the code?

I don't think so. The very first step of Clojure's expression processing system, the reader, already interprets 1.1 as a floating- point constant. You would need your own reader to give a different meaning to the input string 1.1. However, the good news is that you would only need a different reader, you could then plug its results into the standard evaluation system.

Konrad.

--
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

Reply via email to