Re: (float 0.819869321599107) = 0.81986934 ?
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 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: (float 0.819869321599107) = 0.81986934 ?
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. > > 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 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 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 function-name-here) >>> >>> (find-doc "part-of-name-here") >>> >>> Source: (source function-name-here) >>> >>> Javadoc: (javadoc java-object-or-class-here) >>> >>> Exit: Control+D or (exit) or (quit) >>> >>> Results: Stored in vars *1, *2, *3, an exception in *e >>> >>> >>> user=> (float 0.819869321599107) >>> >>> 0.81986934 >>> >>> user=> >>> >>> >>> Thanks in advance. >>> >>> >>> Sincerely, >>> >>> Ru >>> >> -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: (float 0.819869321599107) = 0.81986934 ?
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 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 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 function-name-here) >> >> (find-doc "part-of-name-here") >> >> Source: (source function-name-here) >> >> Javadoc: (javadoc java-object-or-class-here) >> >> Exit: Control+D or (exit) or (quit) >> >> Results: Stored in vars *1, *2, *3, an exception in *e >> >> >> user=> (float 0.819869321599107) >> >> 0.81986934 >> >> user=> >> >> >> Thanks in advance. >> >> >> Sincerely, >> >> Ru >> > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: (float 0.819869321599107) = 0.81986934 ?
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 at 2:21 PM ru wrote: > 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 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 function-name-here) >> >> (find-doc "part-of-name-here") >> >> Source: (source function-name-here) >> >> Javadoc: (javadoc java-object-or-class-here) >> >> Exit: Control+D or (exit) or (quit) >> >> Results: Stored in vars *1, *2, *3, an exception in *e >> >> >> user=> (float 0.819869321599107) >> >> 0.81986934 >> >> user=> >> >> >> Thanks in advance. >> >> >> Sincerely, >> >> Ru >> > -- > 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 > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: (float 0.819869321599107) = 0.81986934 ?
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 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 function-name-here) > > (find-doc "part-of-name-here") > > Source: (source function-name-here) > > Javadoc: (javadoc java-object-or-class-here) > > Exit: Control+D or (exit) or (quit) > > Results: Stored in vars *1, *2, *3, an exception in *e > > > user=> (float 0.819869321599107) > > 0.81986934 > > user=> > > > Thanks in advance. > > > Sincerely, > > Ru > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: (float 0.819869321599107) = 0.81986934 ?
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 into the details of this, this article may interest you: "What Every Computer Scientist Should Know About Floating-Point Arithmetic" https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html There is a whole field of study called "numerical analysis" where people study and quantify how much error can be introduced in programs that calculate using floating point values in different ways. Two programs that according to algebra will calculate the same value, can calculate values with much different 'error ranges' from each other: https://en.wikipedia.org/wiki/Numerical_analysis There are Fortran libraries that are used _because_ the language specifies the order of operations and how they relate to the source code, so the programmer has control over such things, i.e. the compiler is _not allowed_ to make certain kinds of transformations that may appear equivalent to the source code according to the usual rules of algebra. Andy On Sat, Dec 15, 2018 at 10:11 AM ru wrote: > 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 function-name-here) > > (find-doc "part-of-name-here") > > Source: (source function-name-here) > > Javadoc: (javadoc java-object-or-class-here) > > Exit: Control+D or (exit) or (quit) > > Results: Stored in vars *1, *2, *3, an exception in *e > > > user=> (float 0.819869321599107) > > 0.81986934 > > user=> > > > Thanks in advance. > > > Sincerely, > > Ru > > -- > 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 > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: (float 0.819869321599107) = 0.81986934 ?
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 AM Alan Thompson wrote: > 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 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 function-name-here) >> >> (find-doc "part-of-name-here") >> >> Source: (source function-name-here) >> >> Javadoc: (javadoc java-object-or-class-here) >> >> Exit: Control+D or (exit) or (quit) >> >> Results: Stored in vars *1, *2, *3, an exception in *e >> >> >> user=> (float 0.819869321599107) >> >> 0.81986934 >> >> user=> >> >> >> Thanks in advance. >> >> >> Sincerely, >> >> Ru >> >> -- >> 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 >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: (float 0.819869321599107) = 0.81986934 ?
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 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 function-name-here) > > (find-doc "part-of-name-here") > > Source: (source function-name-here) > > Javadoc: (javadoc java-object-or-class-here) > > Exit: Control+D or (exit) or (quit) > > Results: Stored in vars *1, *2, *3, an exception in *e > > > user=> (float 0.819869321599107) > > 0.81986934 > > user=> > > > Thanks in advance. > > > Sincerely, > > Ru > > -- > 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 > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
(float 0.819869321599107) = 0.81986934 ?
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 function-name-here) (find-doc "part-of-name-here") Source: (source function-name-here) Javadoc: (javadoc java-object-or-class-here) Exit: Control+D or (exit) or (quit) Results: Stored in vars *1, *2, *3, an exception in *e user=> (float 0.819869321599107) 0.81986934 user=> Thanks in advance. Sincerely, Ru -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.