Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue3008] Let bin/oct/hex show floats

 

 

First page Previous page 1 2 Next page Last page  View All Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Jun 24, 2008, 6:25 PM

Post #1 of 37 (389 views)
Permalink
[issue3008] Let bin/oct/hex show floats

Changes by Raymond Hettinger <rhettinger[at]users.sourceforge.net>:


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

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 24, 2008, 10:03 PM

Post #2 of 37 (387 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Raymond Hettinger <rhettinger[at]users.sourceforge.net> added the comment:

Updating patch so that the global symbol starts with _Py.

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

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 25, 2008, 1:30 AM

Post #3 of 37 (379 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Mark Dickinson <dickinsm[at]gmail.com> 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 <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 25, 2008, 9:09 AM

Post #4 of 37 (371 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Raymond Hettinger <rhettinger[at]users.sourceforge.net> added the comment:

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

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 25, 2008, 10:40 AM

Post #5 of 37 (370 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Mark Dickinson <dickinsm[at]gmail.com> 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 <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 25, 2008, 10:52 AM

Post #6 of 37 (370 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Raymond Hettinger <rhettinger[at]users.sourceforge.net> added the comment:

Attaching a patch that includes normalization to a leading 1.

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

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 26, 2008, 3:58 AM

Post #7 of 37 (357 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Raymond Hettinger <rhettinger[at]users.sourceforge.net> added the comment:

Add support for non-float floats.

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

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 29, 2008, 4:37 PM

Post #8 of 37 (344 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Mark Dickinson <dickinsm[at]gmail.com> 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 <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 29, 2008, 4:38 PM

Post #9 of 37 (343 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Changes by Mark Dickinson <dickinsm[at]gmail.com>:


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

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 30, 2008, 10:24 AM

Post #10 of 37 (336 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Mark Dickinson <dickinsm[at]gmail.com> 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 <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 30, 2008, 10:24 AM

Post #11 of 37 (335 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Mark Dickinson <dickinsm[at]gmail.com> added the comment:

...and the tests for hex_float.py

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

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 30, 2008, 10:41 AM

Post #12 of 37 (335 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Changes by Mark Dickinson <dickinsm[at]gmail.com>:


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

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 30, 2008, 3:25 PM

Post #13 of 37 (334 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Raymond Hettinger <rhettinger[at]users.sourceforge.net> added the comment:

I'm looking forward to your C implementation.

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 3, 2008, 4:41 PM

Post #14 of 37 (300 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Guido van Rossum <guido[at]python.org> 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 <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 3, 2008, 9:30 PM

Post #15 of 37 (296 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Raymond Hettinger <rhettinger[at]users.sourceforge.net> added the comment:

Mark, I'm tied-up with EuroPython until the 14th. Do you have time to
take a crack at this?

----------
assignee: rhettinger -> marketdickinson

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 4, 2008, 12:13 AM

Post #16 of 37 (294 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Mark Dickinson <dickinsm[at]gmail.com> added the comment:

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

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 4, 2008, 6:45 AM

Post #17 of 37 (286 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Guido van Rossum <guido[at]python.org> added the comment:

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

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 4, 2008, 7:12 AM

Post #18 of 37 (285 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Mark Dickinson <dickinsm[at]gmail.com> added the comment:

Sure. What about non-C99 machines? I thought Python code was only
allowed to assume ANSI C.

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 4, 2008, 7:28 AM

Post #19 of 37 (286 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Guido van Rossum <guido[at]python.org> added the comment:

On Fri, Jul 4, 2008 at 7:12 AM, Mark Dickinson <report[at]bugs.python.org> wrote:
>
> Mark Dickinson <dickinsm[at]gmail.com> added the comment:
>
> Sure. What about non-C99 machines? I thought Python code was only
> allowed to assume ANSI C.

I'm pretty sure that's a thing of the past. Ask MvL.

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 4, 2008, 7:45 AM

Post #20 of 37 (287 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Amaury Forgeot d'Arc <amauryfa[at]gmail.com> added the comment:

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

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 5, 2008, 1:58 AM

Post #21 of 37 (256 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Mark Dickinson <dickinsm[at]gmail.com> 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 <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 5, 2008, 2:02 AM

Post #22 of 37 (257 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Mark Dickinson <dickinsm[at]gmail.com> 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 <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 5, 2008, 4:08 AM

Post #23 of 37 (250 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Mark Dickinson <dickinsm[at]gmail.com> 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 <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 5, 2008, 5:42 AM

Post #24 of 37 (250 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Mark Dickinson <dickinsm[at]gmail.com> added the comment:

Add updated patch with expanded documentation.

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

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 5, 2008, 5:42 AM

Post #25 of 37 (250 views)
Permalink
[issue3008] Let bin/oct/hex show floats [In reply to]

Changes by Mark Dickinson <dickinsm[at]gmail.com>:


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

_______________________________________
Python tracker <report[at]bugs.python.org>
<http://bugs.python.org/issue3008>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

First page Previous page 1 2 Next page Last page  View All Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.