Re: %a format

From: Tim Peters (tim.peters_at_gmail.com)
Date: 09/09/04


Date: Wed, 8 Sep 2004 23:19:14 -0400
To: python-list@python.org


[Martin v. Löwis]
> ...
> For the specific feature, I think a non-libc implementation would be
> possible, since Python uses IEEE representation for floating point
> numbers on most platforms (although atleast the VMS port doesn't
> necessarily). Whether it is reasonable to implement this by mere
> bit copying is a question that Tim Peters should answer :-)

Python has no knowledge of the FP format used by the platform C it's
compiled under. VMS and some Crays may not use IEEE double format for
Python long, but we've got no code that knows (or cares) to build on.
Endianness differs across platforms too, of course.

I don't have a use for %a myself, so I don't care about it. Pickles
are Python's serialization format, and pickle protocols 1 and 2 use a
portable binary format for floats that happens to be identical to 754
double format for finite non-0 floats (and so is also restricted to
the precision and dynamic range of a 754 double). The other
serialization format is repr(float), which produces a decimal string
representation, and on every IEEE platform with IEEE-conforming libc
I/O, eval(repr(afloat)) == afloat exactly for all finite afloat. So
there are already those two ways to transport a finite 754 float
across boxes exactly. The marshal and struct modules supply two more
(although marshal relies on repr(); and struct in its standard modes
copy-and-paste duplicates cPickle's code). I don't need five ways to
spell it <wink>.



Relevant Pages

  • Re: pickle broken: cant handle NaN or Infinity under win32
    ... > The number of distinct NaNs varies among platforms. ... According to the IEEE standard, ... Python has _tons_ of platform-specific code in it. ...
    (comp.lang.python)
  • Re: Smallest float different from 0.0?
    ... if Python ever switched to using IEEE 754 binary128 format (or some ...
    (comp.lang.python)
  • Re: Smallest float different from 0.0?
    ... limit constants) to get the smallest positive float that Python ... if Python ever switched to using IEEE 754 binary128 format (or some ...
    (comp.lang.python)
  • Re: cobol data format!!! urgent!!!
    ... misunderstood what "conformance to a standard" means. ... Cobol people 'know' binary floating-point is ... The quotation above is from IEEE 754. ... same as the IBM System/390 format which isn't the same as the Unisys MCP ...
    (comp.lang.cobol)
  • RfD: IEEE-FP 0.5.2
    ... the default format can be any IEEE binary ... restored to *nearly* the same as DPANS94 ... IEEE comparisons reworked ... This is a proposal for an optional Forth 200x word set, ...
    (comp.lang.forth)

Loading