Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98914

Re: Problems using struct pack/unpack in files, and reading them.

Path csiph.com!news.mixmin.net!weretis.net!feeder4.news.weretis.net!ecngs!testfeeder.ecngs.de!81.171.118.62.MISMATCH!peer02.fr7!news.highwinds-media.com!post02.fr7!fx35.am4.POSTED!not-for-mail
From Dave Farrance <df@see.replyto.invalid>
Newsgroups comp.lang.python
Subject Re: Problems using struct pack/unpack in files, and reading them.
Reply-To DaveFarrance@yahoo.co.uk.invalid
Message-ID <5isl4bpluclfm0fhj3aa7a4u4gj1n2c4nh@4ax.com> (permalink)
References <mailman.310.1447454532.16136.python-list@python.org> <56469f14$0$1612$c3e8da3$5496439d@news.astraweb.com> <mailman.314.1447470111.16136.python-list@python.org> <5646c95a$0$1597$c3e8da3$5496439d@news.astraweb.com> <mailman.329.1447515842.16136.python-list@python.org> <87vb94ikuv.fsf@elektro.pacujo.net> <mailman.334.1447520685.16136.python-list@python.org> <datajrF7ojoU2@mid.individual.net> <5649c807$0$1615$c3e8da3$5496439d@news.astraweb.com>
X-Newsreader Forte Agent on Wine 5.00/32.1171
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
Lines 32
NNTP-Posting-Host 80.193.198.211
X-Complaints-To http://netreport.virginmedia.com
X-Trace 1447754071 80.193.198.211 (Tue, 17 Nov 2015 09:54:31 UTC)
NNTP-Posting-Date Tue, 17 Nov 2015 09:54:31 UTC
Organization virginmedia.com
Date Tue, 17 Nov 2015 09:54:31 +0000
X-Received-Body-CRC 4049498251
X-Received-Bytes 1976
Xref csiph.com comp.lang.python:98914

Show key headers only | View raw


Steven D'Aprano <steve@pearwood.info> wrote:

>On Mon, 16 Nov 2015 05:15 pm, Gregory Ewing wrote:
>
>> Ints are not the only thing that // can be applied to:
>> 
>>  >>> 1.0//0.01
>> 99.0
>
>Good catch!

Hmmm. I see that the float for 0.01 _is_ slightly larger than 0.01

>>> Decimal(0.01)
Decimal('0.01000000000000000020816681711721685132943093776702880859375')

But it seems that 1.0 // 0.01 is not directly equivalent to:

>>> int(1.0 / 0.01)
100

And I see that:

>>> Decimal(1.0 / 0.01)
Decimal('100')
>>> floor(1.0 / 0.01)
100
>>> 0.01 * 100.0 - 1.0
0.0

So I guess that the // operator is _very_ strict in its "floor division"
of floats, but that the "/" operator returns the nearest float value.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-14 09:42 +1100
  Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-14 13:40 +1100
    Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-14 14:01 +1100
      Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-14 16:40 +1100
        Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-14 08:43 -0700
          Re: Problems using struct pack/unpack in files, and reading them. Marko Rauhamaa <marko@pacujo.net> - 2015-11-14 18:52 +0200
            Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-15 04:04 +1100
              Re: Problems using struct pack/unpack in files, and reading them. Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-11-16 19:19 +1300
            Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-14 10:04 -0700
              Re: Problems using struct pack/unpack in files, and reading them. Marko Rauhamaa <marko@pacujo.net> - 2015-11-14 23:53 +0200
              Re: Problems using struct pack/unpack in files, and reading them. Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-11-16 19:15 +1300
                Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-16 23:11 +1100
                Re: Problems using struct pack/unpack in files, and reading them. Dave Farrance <df@see.replyto.invalid> - 2015-11-17 09:54 +0000
            Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-14 10:13 -0700
            Re: Problems using struct pack/unpack in files, and reading them. Random832 <random832@fastmail.com> - 2015-11-14 17:53 -0500
              Re: Problems using struct pack/unpack in files, and reading them. Marko Rauhamaa <marko@pacujo.net> - 2015-11-15 02:12 +0200
              Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-15 12:14 +1100
                Re: Problems using struct pack/unpack in files, and reading them. Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-11-15 11:09 -0500
                Re: Problems using struct pack/unpack in files, and reading them. Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-11-16 19:11 +1300
            Re: Problems using struct pack/unpack in files, and reading them. MRAB <python@mrabarnett.plus.com> - 2015-11-15 00:49 +0000
          Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-15 13:08 +1100
            Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-15 13:23 +1100
              Re: Problems using struct pack/unpack in files, and reading them. Steven D'Aprano <steve@pearwood.info> - 2015-11-17 00:17 +1100
                Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-17 00:27 +1100
        Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-15 03:59 +1100
    Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-13 20:45 -0700
    Re: Problems using struct pack/unpack in files, and reading them. Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-13 20:48 -0700
    Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-14 14:56 +1100
    Re: Problems using struct pack/unpack in files, and reading them. Chris Angelico <rosuav@gmail.com> - 2015-11-14 14:57 +1100

csiph-web