Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39469
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Peter Pearson <ppearson@nowhere.invalid> |
| Newsgroups | comp.lang.python |
| Subject | Re: Confusing math problem |
| Date | 21 Feb 2013 21:59:54 GMT |
| Lines | 33 |
| Message-ID | <aonjmqFqplbU1@mid.individual.net> (permalink) |
| References | <kg5sog$lfb$1@dont-email.me> <512682B3.8070909@davea.name> <51268867.1000800@davea.name> <mailman.2199.1361481815.2939.python-list@python.org> |
| X-Trace | individual.net sQZ1jO0MqZ2wR9heqbpZnQRQKu2XWnQJi4rcks/6boSkno1EfeaIfyG6HA6Myopj1b |
| Cancel-Lock | sha1:RJZo9GFLHNLLm3+s/zG/HJ7Mdd8= |
| User-Agent | slrn/pre1.0.0-18 (Linux) |
| Xref | csiph.com comp.lang.python:39469 |
Show key headers only | View raw
On Fri, 22 Feb 2013 08:23:27 +1100, Chris Angelico <rosuav@gmail.com> wrote: > On Fri, Feb 22, 2013 at 7:49 AM, Dave Angel <davea@davea.name> wrote: >> However, if I do: >> >> print 3**60, "\n", int(math.pow(3,60)), "\n", pow(3,60) >> >> >> I get: >> >> 42391158275216203514294433201 >> 42391158275216203520420085760 >> 42391158275216203514294433201 >> >> >> and the middle one is the one that's wrong. > > In theory, a float should hold the nearest representable value to the > exact result. Considering that only one operation is being performed, > there should be no accumulation of error. The integer results show a > small number (618) of collisions, eg 2**16 and 4**8; why should some > of those NOT collide when done with floating point? My initial thought > was "Oh, this is comparing floats for equality", but after one single > operation, that should be not a problem. Does this help explain it? >>> print hex(int(math.pow(3,60))); print hex(3**60) 0x88f924eeceeda80000000000L 0x88f924eeceeda7fe92e1f5b1L -- To email me, substitute nowhere->spamcop, invalid->net.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Confusing math problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-21 19:33 +0000
Re: Confusing math problem Dave Angel <davea@davea.name> - 2013-02-21 15:25 -0500
Re: Confusing math problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-21 22:39 +0000
Re: Confusing math problem Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-21 22:53 +0000
Re: Confusing math problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-21 23:41 +0000
Re: Confusing math problem Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-22 00:04 +0000
Re: Confusing math problem Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-21 17:19 -0700
Re: Confusing math problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-21 23:39 +0000
Re: Confusing math problem Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-21 13:42 -0700
Re: Confusing math problem Chris Angelico <rosuav@gmail.com> - 2013-02-22 07:46 +1100
Re: Confusing math problem "Schizoid Man" <schiz_man@21stcentury.com> - 2013-02-21 22:44 +0000
Re: Confusing math problem Chris Angelico <rosuav@gmail.com> - 2013-02-22 11:29 +1100
Re: Confusing math problem Dave Angel <davea@davea.name> - 2013-02-21 21:19 -0500
Re: Confusing math problem Dave Angel <davea@davea.name> - 2013-02-21 15:49 -0500
Re: Confusing math problem Chris Angelico <rosuav@gmail.com> - 2013-02-22 08:23 +1100
Re: Confusing math problem Peter Pearson <ppearson@nowhere.invalid> - 2013-02-21 21:59 +0000
Re: Confusing math problem Chris Angelico <rosuav@gmail.com> - 2013-02-22 09:11 +1100
Re: Confusing math problem Dave Angel <davea@davea.name> - 2013-02-21 17:33 -0500
Re: Confusing math problem Chris Angelico <rosuav@gmail.com> - 2013-02-22 10:15 +1100
Re: Confusing math problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-22 09:16 +0000
Re: Confusing math problem Serhiy Storchaka <storchaka@gmail.com> - 2013-02-22 13:48 +0200
Re: Confusing math problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-22 09:27 +0000
csiph-web