Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20945
| Date | 2012-02-27 08:34 -0700 |
|---|---|
| From | Michael Torrie <torriem@gmail.com> |
| Subject | Re: Python math is off by .000000000000045 |
| References | <mailman.49.1329934400.3037.python-list@python.org> <99543cae-b494-409e-9ac1-073639dcf224@p7g2000yqk.googlegroups.com> <4f4af847$0$29999$c3e8da3$5496439d@news.astraweb.com> <jig5ur$e97$1@reader1.panix.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.203.1330356912.3037.python-list@python.org> (permalink) |
On 02/27/2012 08:02 AM, Grant Edwards wrote: > On 2012-02-27, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: >> On Sun, 26 Feb 2012 16:24:14 -0800, John Ladasky wrote: >> >>> Curiosity prompts me to ask... >>> >>> Those of you who program in other languages regularly: if you visit >>> comp.lang.java, for example, do people ask this question about >>> floating-point arithmetic in that forum? Or in comp.lang.perl? >> >> Yes. >> >> http://stackoverflow.com/questions/588004/is-javascripts-math-broken >> >> And look at the "Linked" sidebar. Obviously StackOverflow users no >> more search the internet for the solutions to their problems than do >> comp.lang.python posters. >> >> http://compgroups.net/comp.lang.java.programmer/Floating-point-roundoff-error > > One might wonder if the frequency of such questions decreases as the > programming language becomes "lower level" (e.g. C or assembly). I think that most of the use cases in C or assembly of math are integer-based only. For example, counting, bit-twiddling, addressing character cells or pixel coordinates, etc. Maybe when programmers have to statically declare a variable type in advance, since the common use cases require only integer, that gets used far more, so experiences with float happen less often. Some of this could have to do with the fact that historically floating point required a special library to do floating point math, and since a lot of people didn't have floating-point coprocessors back then, most code was integer-only. Early BASIC interpreters defaulted to floating point for everything, and implemented all the floating point arithmetic internally with integer arithmetic, without the help of the x87 processor, but no doubt they did round the results when printing to the screen. They also did not have very much precision to begin with. Anyone remember Microsoft's proprietary floating point binary system and how there were function calls to convert back and forth between the IEEE standard? Another key thing is that most C programmers don't normally just print out floating point numbers without a %.2f kind of notation that properly rounds a number. Now, of course, every processor has a floating-point unit, and the C compilers can generate code that uses it just as easily as integer code. No matter what language, or what floating point scheme you use, significant digits is definitely important to understand!
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Python math is off by .000000000000045 Alec Taylor <alec.taylor6@gmail.com> - 2012-02-23 05:13 +1100
Re: Python math is off by .000000000000045 nn <pruebauno@latinmail.com> - 2012-02-22 10:29 -0800
Re: Python math is off by .000000000000045 Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-02-22 20:44 +0200
Re: Python math is off by .000000000000045 Grant Edwards <invalid@invalid.invalid> - 2012-02-22 20:48 +0000
Re: Python math is off by .000000000000045 Tobiah <toby@tobiah.org> - 2012-02-25 09:56 -0800
Re: Python math is off by .000000000000045 Tim Wintle <tim.wintle@teamrubber.com> - 2012-02-25 19:08 +0000
Re: Python math is off by .000000000000045 Terry Reedy <tjreedy@udel.edu> - 2012-02-25 16:05 -0500
Re: Python math is off by .000000000000045 jmfauth <wxjmfauth@gmail.com> - 2012-02-25 13:25 -0800
Re: Python math is off by .000000000000045 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-25 22:51 +0000
Re: Python math is off by .000000000000045 jmfauth <wxjmfauth@gmail.com> - 2012-02-26 01:59 -0800
Re: Python math is off by .000000000000045 Ethan Furman <ethan@stoneleaf.us> - 2012-02-27 09:28 -0800
Re: Python math is off by .000000000000045 Michael Torrie <torriem@gmail.com> - 2012-02-27 17:53 -0700
Re: Python math is off by .000000000000045 Ethan Furman <ethan@stoneleaf.us> - 2012-02-28 09:56 -0800
Re: Python math is off by .000000000000045 Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-02-25 21:49 -0500
Re: Python math is off by .000000000000045 Terry Reedy <tjreedy@udel.edu> - 2012-02-26 00:44 -0500
Re: Python math is off by .000000000000045 John Ladasky <ladasky@my-deja.com> - 2012-02-26 16:24 -0800
Re: Python math is off by .000000000000045 Terry Reedy <tjreedy@udel.edu> - 2012-02-26 20:30 -0500
Re: Python math is off by .000000000000045 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-27 03:28 +0000
Re: Python math is off by .000000000000045 Grant Edwards <invalid@invalid.invalid> - 2012-02-27 15:02 +0000
Re: Python math is off by .000000000000045 Michael Torrie <torriem@gmail.com> - 2012-02-27 08:34 -0700
csiph-web