[issue3008] Let bin/oct/hex show floats

2008-07-15 Thread Mark Dickinson

Changes by Mark Dickinson [EMAIL PROTECTED]:


___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-15 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

Here's an updated patch that addresses Raymond's concerns.

 The patch looks good.  I would coded hex_from_char() using a lookup 
 into 0123456789abcdef which uses no unpredicatable branches.  
 Likewise, I would done hex_from_char() with a case statement (limiting 
 the call to single unpredicatable branch).

Done.

 Question:  are the (0x0p+0) and (-0x0p+0) special cases standard?

Not entirely.  Java outputs 0x0.0p0 and -0x0.0p0.  The C99 standard 
doesn't specify exactly how the output should look, except to say that 
the exponent should be 0.  The '+' is there for consistency.

I can change '0x0p+0' to '0x0.0p+0' if people think this looks prettier.
On consideration, this does look better to me.  Changed.

 The docs need a new in py2.6

Fixed.

 Coding style:  move the inner si++ to a separate line so there are no 
 side-effects and the order of execution is obvious.

Done.  (And the same with s++ in float_fromhex.)

 Question:  should the inf string checks be made case sensitive on 
 insensitive?  Is there a standard?

Everything I've seen, except Java, seems to like case-insensitivity.  
The C99 standard says case should be ignored, as does the IBM Decimal 
standard.  Python's float('nan') and float('inf') also currently ignore 
case.  So I think these checks should be case insensitive.

(Java insists on infinity being spelt Infinity, and nan being spelt 
NaN.)

Thank you for reviewing this, Raymond!

I aim to check this in when (if?) I get approval from Barry.

Added file: http://bugs.python.org/file10897/hex_float9.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-15 Thread Guido van Rossum

Guido van Rossum [EMAIL PROTECTED] added the comment:

If you two can agree that this code is good, I'm ok with the API.

I would emphasize in the docs and NEWS entry though that .hex() is an
*instance* method while .fromhex() is a *class* method.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-15 Thread Raymond Hettinger

Raymond Hettinger [EMAIL PROTECTED] added the comment:

Mark, please go ahead and apply so the buildbots will have time to give 
it a run on all the platforms before beta 2 is cut.  Be sure to make 
Guido's edits to the Misc/NEWS entry.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-14 Thread Raymond Hettinger

Raymond Hettinger [EMAIL PROTECTED] added the comment:

The patch looks good.  I would coded hex_from_char() using a lookup 
into 0123456789abcdef which uses no unpredicatable branches.  
Likewise, I would done hex_from_char() with a case statement (limiting 
the call to single unpredicatable branch).

Question:  are the (0x0p+0) and (-0x0p+0) special cases standard?

The docs need a new in py2.6

Coding style:  move the inner si++ to a separate line so there are no 
side-effects and the order of execution is obvious.

Question:  should the inf string checks be made case sensitive on 
insensitive?  Is there a standard?

--
resolution:  - accepted

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-13 Thread Raymond Hettinger

Raymond Hettinger [EMAIL PROTECTED] added the comment:

So far this looks good.  Will complete the review on the next leg of my 
flight (about 12 hrs).

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-12 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

Here's an updated patch that makes the trailing 'p123' exponent optional 
in fromhex.  (This matches the behaviour of C99's strtod and sscanf;  in 
contrast, Java always requires the exponent.)

I'm beginning to wonder whether the '0x' shouldn't also be optional on 
input as well, in the same way that it's optional in int():

 int('0x45', 16)
69
 int('45', 16)
69

This would then allow, e.g.,

 float.fromhex('45')
69.0

Added file: http://bugs.python.org/file10881/hex_float6.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-12 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

In the spirit of being liberal in what you accept, but strict in what you 
emit, here's a version that makes both the leading '0x' and the trailing 
'p...' exponent optional on input.  Both of these are still produced on 
output.

Note that this version is still perfectly interoperable with C99 and Java 
1.5+:  fromhex accepts anything produced by C and Java (e.g. via C's '%a', 
or Java's toHexString), and the output of hex can be read by C99's 
strtod/sscanf and Java's Double constructor, and/or used as hex literals 
in C or Java source.

Added file: http://bugs.python.org/file10882/hex_float7.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-12 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

Some final tinkering:

 - docstrings and docs expanded slightly;  docs mention interoperability
with C and Java.

 - in float.hex(), there's always a sign included in the exponent (e.g. 
0x1p+0 instead of 0x1p0).  This just makes for a little bit more 
consistency with repr(float), with C99 and with the way the Decimal module 
behaves (but not with Java, which omits the + sign).

Added file: http://bugs.python.org/file10884/hex_float8.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-11 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

Minor modifications to the previous patch,  mostly to the docs.

Setting priority to critical, since this really needs to go in before the 
next beta if it's going to get into 2.6/3.0.

--
priority:  - critical
Added file: http://bugs.python.org/file10876/hex_float5.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-10 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

Here's a slightly more polished version of the previous patch;  no
behaviour changes.

Let me know if there's anything I can do to help get this in before next 
week's beta.  Anybody want to trade patch reviews?

Added file: http://bugs.python.org/file10874/hex_float4.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-05 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

In the interests of getting early feedback, here's half a patch, 
containing an implementation of from.fromhex and tests.

Still to come:  float.hex and documentation.

I'll ask on python-dev about C99 and %a.

Added file: http://bugs.python.org/file10814/hex_float.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-05 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

 containing an implementation of from.fromhex and tests.

That should be 'float.fromhex', not 'from.fromhex'.
I should also have said that this patch is against the trunk;  only minor 
changes should be required for py3k.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-05 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

Here's an updated patch, complete with both float methods and 
documentation.

Added file: http://bugs.python.org/file10815/hex_float2.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-05 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

Add updated patch with expanded documentation.

Added file: http://bugs.python.org/file10816/hex_float2.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-05 Thread Mark Dickinson

Changes by Mark Dickinson [EMAIL PROTECTED]:


Removed file: http://bugs.python.org/file10815/hex_float2.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-04 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

I'm working on it.  I expect to have something ready by the end of this 
weekend.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-04 Thread Guido van Rossum

Guido van Rossum [EMAIL PROTECTED] added the comment:

BTW couldn't you use the %a feature built into C99 to implement this?
(Both input and output?)

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-04 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc [EMAIL PROTECTED] added the comment:

Microsoft compilers implement %a since VS8.0. 
VS7.1 does not have it.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-07-03 Thread Guido van Rossum

Guido van Rossum [EMAIL PROTECTED] added the comment:

Raymond, Mark?  Is a new patch with tests and docs forthcoming?  Have
you decided on the API yet?  I'm willing to approve this for beta 2,
which will be around July 15.

--
assignee: gvanrossum - rhettinger

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-06-30 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

Here's an updated Python version of toHex and fromHex; fixes a bug in the 
previous version of fromHex for hex floats starting with an upper case hex 
digit.  I'm not sure how useful this is, but I thought I might as well 
post the code.

I also have tests for these;  to follow.

I'd be happy to help out with the C version once the API is decided on;  I 
have far too much time on my hands right now.  Though I'm assuming Raymond 
will beat me to it.

Added file: http://bugs.python.org/file10785/hex_float.py

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-06-30 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

...and the tests for hex_float.py

Added file: http://bugs.python.org/file10786/test_hex_float.py

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-06-30 Thread Mark Dickinson

Changes by Mark Dickinson [EMAIL PROTECTED]:


Removed file: http://bugs.python.org/file10780/hex_float.py

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-06-30 Thread Raymond Hettinger

Raymond Hettinger [EMAIL PROTECTED] added the comment:

I'm looking forward to your C implementation.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-06-29 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

Here's some Python code to translate floats to hex strings and back, in 
case it's useful.

Added file: http://bugs.python.org/file10780/hex_float.py

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-06-29 Thread Mark Dickinson

Changes by Mark Dickinson [EMAIL PROTECTED]:


Removed file: http://bugs.python.org/file10729/hex_float.py

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-06-25 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

 -1 on Nick's suggestion to normalize hex output so that nearby floats 
 have nearby reprs.  This unnecessarily complicates a simple, straight-
 forward presentation.  In the paper referenced by Terry Reedy, 
 normalized presentations were not used

As far as I can tell, that paper *does* use normalized presentations:  
with the exception of subnormals and zeros, all hex floats have a leading 
digit of 1.  This is the same normalization that Java's toHexString uses, 
and that C's printf %a format modifier uses on all machines that I've 
tested (though the C standards don't seem to lay down the law on this).

I think this is helpful.  For example, on the first page of section 4.1 of 
the paper Terry Reedy references, the author gives two different results 
produced by running the same sin() computation on different systems.  The 
results are:

-0x1.95b011554d4b5p-1

and

-0x1.95b0115490ca6p-1.

Looking at these results, it's readily apparent that the error is somewhat 
less than 1000 ulps.  But the current hex() output for these two numbers 
is:

'-0x195b011554d4b5 * 2.0 ** -53'

and

'-0xcad808aa48653 * 2.0 ** -52'

It's much less clear that these numbers are close, or how close they are.

I guess I just have a feeling that changes to the least significant bits 
of a number shouldn't produce big changes in its representation.

 and I've never seen that done anywhere else.

I'm not sure I've ever seen this *not* done anywhere else.

P.S. You should blame me for the normalization comment, not Nick. :)

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-06-25 Thread Raymond Hettinger

Raymond Hettinger [EMAIL PROTECTED] added the comment:

How would the algorithm need to change to support leading-1 
normalization?

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-06-25 Thread Mark Dickinson

Mark Dickinson [EMAIL PROTECTED] added the comment:

Well, here's some Python code to output C99-style hexadecimal 
representations of floats.  It's not quite the same as Java's output, 
which also special cases IEEE 754 subnormals (writing them with a fixed 
exponent of -1022 and a '0' before the point).  But then Python doesn't 
have the luxury of knowing that its floats are IEEE 754 format.

The big downside is that the output format has a decimal point in it, so 
won't be eval-able.

Added file: http://bugs.python.org/file10729/hex_float.py

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-06-25 Thread Raymond Hettinger

Raymond Hettinger [EMAIL PROTECTED] added the comment:

Attaching a patch that includes normalization to a leading 1.

Added file: http://bugs.python.org/file10731/float8.diff

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-06-24 Thread Raymond Hettinger

Changes by Raymond Hettinger [EMAIL PROTECTED]:


--
assignee: rhettinger - gvanrossum
nosy: +gvanrossum
title: Let bin() show floats - Let bin/oct/hex show floats

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3008] Let bin/oct/hex show floats

2008-06-24 Thread Raymond Hettinger

Raymond Hettinger [EMAIL PROTECTED] added the comment:

Updating patch so that the global symbol starts with _Py.

Added file: http://bugs.python.org/file10726/float7.diff

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3008
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com