Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20960
| Date | 2012-02-27 17:53 -0700 |
|---|---|
| From | Michael Torrie <torriem@gmail.com> |
| Subject | Re: Python math is off by .000000000000045 |
| References | (3 earlier) <mailman.162.1330203944.3037.python-list@python.org> <aa5ca147-b5ed-4f8c-935d-48b2c2cfac87@gr6g2000vbb.googlegroups.com> <4f4965f5$0$29989$c3e8da3$5496439d@news.astraweb.com> <cbd3219a-d379-4499-94ea-c4d0178a498f@db5g2000vbb.googlegroups.com> <4F4BBD4C.1050603@stoneleaf.us> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.210.1330390434.3037.python-list@python.org> (permalink) |
On 02/27/2012 10:28 AM, Ethan Furman wrote: > jmfauth wrote: >> On 25 fév, 23:51, Steven D'Aprano <steve >> +comp.lang.pyt...@pearwood.info> wrote: >>> On Sat, 25 Feb 2012 13:25:37 -0800, jmfauth wrote: >>>>>>> (2.0).hex() >>>> '0x1.0000000000000p+1' >>>>>>> (4.0).hex() >>>> '0x1.0000000000000p+2' >>>>>>> (1.5).hex() >>>> '0x1.8000000000000p+0' >>>>>>> (1.1).hex() >>>> '0x1.199999999999ap+0' >>>> jmf >>> What's your point? I'm afraid my crystal ball is out of order and I have >>> no idea whether you have a question or are just demonstrating your >>> mastery of copy and paste from the Python interactive interpreter. >> >> It should be enough to indicate the right direction >> for casual interested readers. > > I'm a casual interested reader and I have no idea what your post is > trying to say. He's simply showing you the hex (binary) representation of the floating-point number's binary representation. As you can clearly see in the case of 1.1, there is no finite sequence that can store that. You end up with repeating numbers. Just like 1/3, when represented in base 10 fractions (x1/10 + x2/100, x3/1000, etc), is a repeating sequence, the number base 10 numbers 1.1 or 0.2, or many others that are represented by exact base 10 fractions, end up as repeating sequences in base 2 fractions. This should help you understand why you get errors doing simple things like x/y*y doesn't quite get you back to x.
Back to comp.lang.python | Previous | Next — Previous in thread | Next 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