Re: (float 0.819869321599107) = 0.81986934 ?

2018-12-15 Thread Andy Fingerhut
As mentioned in other responses, floating point numbers are usually approximations, with round-off error in the least significant digits (both floats and doubles do this, with more digits of precision for doubles, at the cost of more storage in memory). Depending on how deeply you want to dive

Re: (float 0.819869321599107) = 0.81986934 ?

2018-12-15 Thread Daniel
If you want more precise rounding to the 8th decimal then with-precision is available for BigDecimals. The literal representation will look just like the float you wanted. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send

Re: (float 0.819869321599107) = 0.81986934 ?

2018-12-15 Thread Andy Fingerhut
The rounding of floats and doubles is _not_ in decimal digits. It is internally implemented in binary, so the rounding behavior you see, while it might not make much sense when written in decimal, probably makes perfect sense if you write it in the IEEE binary format. Andy On Sat, Dec 15, 2018

Re: (float 0.819869321599107) = 0.81986934 ?

2018-12-15 Thread ru
I have to use float in one application. I just thought that a reasonable implementation of the float function could use the rounding we were used to, that is, (float 0.819869321599107) = 0.81986932 суббота, 15 декабря 2018 г., 21:10:54 UTC+3 пользователь ru написал: > > Dear Clojure users and

Re: (float 0.819869321599107) = 0.81986934 ?

2018-12-15 Thread Gary Fredericks
0.81986932 is not a valid float -- the next smallest one is 0.81986930, so the one you were given is the closest that can be rounded to. Try (Math/nextUp x) and (Math/nextDown x) to see what floats are possible. On Saturday, December 15, 2018 at 4:21:05 PM UTC-6, ru wrote: > > I have to use

Re: (float 0.819869321599107) = 0.81986934 ?

2018-12-15 Thread ru
Thank you all for an exhaustive explanation. Sincerely, Ru воскресенье, 16 декабря 2018 г., 3:11:56 UTC+3 пользователь Gary Fredericks написал: > > 0.81986932 is not a valid float -- the next smallest one is 0.81986930, so > the one you were given is the closest that can be rounded to. > >

Re: `lein test` 28x slower than `lein run`.... Why?

2018-12-15 Thread Alan Thompson
Never mind, I found the problem. During testing I had enabled Plumatic Schema function validation: (s/set-fn-validation! true) ; enforce fn schemas Disabling validation made `lein test` and `lein run` produce comparable times. Alan On Sat, Dec 15, 2018 at 10:41 AM Alan Thompson wrote:

(float 0.819869321599107) = 0.81986934 ?

2018-12-15 Thread ru
Dear Clojure users and team! Please explain me this result: Ruslans-iMac:clojure ru$ lein repl nREPL server started on port 54147 on host 127.0.0.1 - nrepl://127.0.0.1:54147 REPL-y 0.3.7, nREPL 0.2.12 Clojure 1.8.0 Java HotSpot(TM) 64-Bit Server VM 11.0.1+13-LTS Docs: (doc

Re: (float 0.819869321599107) = 0.81986934 ?

2018-12-15 Thread Alan Thompson
An IEEE-754 floating point value has only 32 bits (total), which corresponds to approximately 8 decimal digits. For full info, see the java spec: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Float.html On Sat, Dec 15, 2018 at 10:11 AM ru wrote: > Dear Clojure users

Re: (float 0.819869321599107) = 0.81986934 ?

2018-12-15 Thread Alan Thompson
For more precision, use `double`, which is a 64-bit double-precision floating-point value (float 0.819869321599107) => 0.81986934 (double 0.819869321599107) => 0.819869321599107 https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Double.html On Sat, Dec 15, 2018 at 10:18

`lein test` 28x slower than `lein run`.... Why?

2018-12-15 Thread Alan Thompson
Hi, I'm seeing something I never expected with Leiningen, namely that `lein test` can take 28x longer to run a task than if it is invoked via `lein run`. Elapsed time measurements (sec): * function test run ratio* :add-tree-xml