[Python-Dev] [Python-checkins] r64424 - in python/trunk:Include/object.h Lib/test/test_sys.py Misc/NEWSObjects/intobject.c Objects/longobject.c Objects/typeobject.cPython/bltinmodule.c (original) (raw)

Mark Dickinson dickinsm at gmail.com
Thu Jun 26 22:17:48 CEST 2008


On Thu, Jun 26, 2008 at 8:55 PM, "Martin v. Löwis" <martin at v.loewis.de> wrote:

I think the feature is misguided in the first place. Why do you want a hex representation of floating point numbers?

Answering for myself: because it gives an exact representation of a floating-point number in a fairly human-readable format.

Can't you use struct.pack for that?

struct.pack would only show the bit layout, leaving the user to manually extract the sign bit, exponent, and fraction, and then make sense of the whole thing. The proposed feature works at a higher level of abstraction, directly describing the value of the float rather than its bit layout. In particular, this means it'll make sense across platforms, regardless of variations in bit layout.

And, if bin/hex/oct are useful, why not base

6 (say)?

I'd say that bin and hex are special: bin is natural because floats are usually thought of, and stored as, binary numbers. hex is special because it gives a compact way of representing a float, and because there's already a history of using hex floats in numerical analysis literature and in programming languages (C99, Java, ...)

I have to admit that I can't see much use for octal floats.

Mark -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20080626/3f79e019/attachment-0001.htm>



More information about the Python-Dev mailing list