[issue3008] Let bin() show floats

2008-06-24 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: Re-opening for further discussion. -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,

[issue3008] Let bin() show floats

2008-06-20 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: Applied in r64438 -- status: open -> closed ___ Python tracker <[EMAIL PROTECTED]> ___

[issue3008] Let bin() show floats

2008-06-20 Thread Mark Dickinson
Mark Dickinson <[EMAIL PROTECTED]> added the comment: > Mark, I added tests for Inf/Nan. Will this work on all platforms? I think the tests should work on all common to semicommon platforms, including on all the buildbots. They won't work on non IEEE 754 platforms (float('nan') will throw an

[issue3008] Let bin() show floats

2008-06-20 Thread Raymond Hettinger
Changes by Raymond Hettinger <[EMAIL PROTECTED]>: Removed file: http://bugs.python.org/file10674/float5.diff ___ Python tracker <[EMAIL PROTECTED]> ___

[issue3008] Let bin() show floats

2008-06-20 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: Mark, I added tests for Inf/Nan. Will this work on all platforms? Added file: http://bugs.python.org/file10675/float5.diff ___ Python tracker <[EMAIL PROTECTED]>

[issue3008] Let bin() show floats

2008-06-20 Thread Raymond Hettinger
Changes by Raymond Hettinger <[EMAIL PROTECTED]>: Added file: http://bugs.python.org/file10674/float5.diff ___ Python tracker <[EMAIL PROTECTED]> ___ __

[issue3008] Let bin() show floats

2008-06-20 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: Hmm, I don't see a way to preserve -0.0 without varying from the standard format. Attaching an updated patch for Amaury's comments. Added file: http://bugs.python.org/file10673/float4.diff ___ Python

[issue3008] Let bin() show floats

2008-06-20 Thread Mark Dickinson
Mark Dickinson <[EMAIL PROTECTED]> added the comment: The patch looks good to me. It's a bit unfortunate that -0.0 doesn't round-trip correctly (the sign of the zero gets lost): >>> eval(bin(-0.0)) 0.0 I don't know whether it's worth special-casing this; the output would have to be in a dif

[issue3008] Let bin() show floats

2008-06-20 Thread Amaury Forgeot d'Arc
Amaury Forgeot d'Arc <[EMAIL PROTECTED]> added the comment: I don't like this modification of a PyString object: + n = PyString_GET_SIZE(conv); + conv_str = PyString_AS_STRING(conv); + /* Remove the trailing 'L' if present */ + if (n && conv_str[n-1] == 'L') +

[issue3008] Let bin() show floats

2008-06-20 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: The other reviewers asked for: * same treatment for oct() and hex() * platform independent exact representation of floats * fixed-size exponential style output instead of tons of leading zeros * output that round-trips through eval() * use

[issue3008] Let bin() show floats

2008-06-19 Thread Raymond Hettinger
Changes by Raymond Hettinger <[EMAIL PROTECTED]>: Added file: http://bugs.python.org/file10667/float2.diff ___ Python tracker <[EMAIL PROTECTED]> ___ __

[issue3008] Let bin() show floats

2008-06-19 Thread Raymond Hettinger
Changes by Raymond Hettinger <[EMAIL PROTECTED]>: Added file: http://bugs.python.org/file10666/float.diff ___ Python tracker <[EMAIL PROTECTED]> ___ ___

[issue3008] Let bin() show floats

2008-06-19 Thread Raymond Hettinger
Changes by Raymond Hettinger <[EMAIL PROTECTED]>: Removed file: http://bugs.python.org/file10664/floatdisp.diff ___ Python tracker <[EMAIL PROTECTED]> ___ _

[issue3008] Let bin() show floats

2008-06-19 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: To address the ideas brought-up so far, here's a new version that can work with eval. The same appoach extends to oct and hex as well: def newbin(f): """ >>> newbin(3.125) '0b11001 * 2.0 ** -3' """ n, d = f.as

[issue3008] Let bin() show floats

2008-06-11 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: Saving this for after the first beta goes out. ___ Python tracker <[EMAIL PROTECTED]> ___ __

[issue3008] Let bin() show floats

2008-06-05 Thread Alexandre Vassalotti
Alexandre Vassalotti <[EMAIL PROTECTED]> added the comment: Kind of a cool hack. I am not sure how useful it is though. Personally, I find ``struct.pack('d', f)`` slightly more educative (more useful too), but that is just me. And if you allow bin() to accept floats, will you make Python accept

[issue3008] Let bin() show floats

2008-06-04 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: No need to conquer the whole world. Start with bin(1.1). If requests pour-in for hex(1.1) or for a reverse routine, we can deal with those when we get them (in the context of their use cases). ___ Py

[issue3008] Let bin() show floats

2008-06-03 Thread Terry J. Reedy
Terry J. Reedy <[EMAIL PROTECTED]> added the comment: > AFAICT, there is no good use case for showing floats in in hex It is my impression that hexadecimal is more common than binary, in the numerical analysis community, for exact representation of floats. For example: http://hal.archives-ouver

[issue3008] Let bin() show floats

2008-05-30 Thread Alexander Belopolsky
Alexander Belopolsky <[EMAIL PROTECTED]> added the comment: On Fri, May 30, 2008 at 2:32 PM, Antoine Pitrou <[EMAIL PROTECTED]> wrote: > then why not make it a method of float? .. because you rarely want to make your functions accept 1.0, but reject 1 and using f.bin() in your function will giv

[issue3008] Let bin() show floats

2008-05-30 Thread Alexander Belopolsky
Alexander Belopolsky <[EMAIL PROTECTED]> added the comment: Another problem with bin() on floats is that it will be a one-way street because as far as I know, there is no function to convert a binary string back to a float. My last thought on this issue is that it will be helpful to add tobase(f

[issue3008] Let bin() show floats

2008-05-30 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: AFAICT, there is no good use case for showing floats in in hex or oct, so those should not chance. Also, since bin() is new, no existing code is affected. Thanks for the comments. ___ Python tracker

[issue3008] Let bin() show floats

2008-05-30 Thread Antoine Pitrou
Antoine Pitrou <[EMAIL PROTECTED]> added the comment: > Better to just build-out bin() and be done with it. Ok, someone has to take a decision anyway. However, if you do that, it should be probably decided first what happens for hex() and oct(). Do they still disallow floats (which is semantica

[issue3008] Let bin() show floats

2008-05-30 Thread Raymond Hettinger
Raymond Hettinger <[EMAIL PROTECTED]> added the comment: Better to just build-out bin() and be done with it. FWIW, the action on ints and floats is similar to how str() handles numeric inputs: str(3) --> '3' str(3.0) --> '3.0' bin(3) --> '0b11' bin(3.0) --> '0b11.0' -- assi

[issue3008] Let bin() show floats

2008-05-30 Thread Antoine Pitrou
Antoine Pitrou <[EMAIL PROTECTED]> added the comment: > What would you say to adding float-capable bin/oct/hex (+ maybe tobase) > to the math module? Why not indeed. However, as I said, if the intent is float-specific (and it is, unless there is another inexact numeric type which warrants a spec

[issue3008] Let bin() show floats

2008-05-30 Thread Antoine Pitrou
Antoine Pitrou <[EMAIL PROTECTED]> added the comment: > I read the proposal as > producing the true mathematical radix 2 representation of a float > rather than its 64-bit memory layout. The term "layout" was probably badly chosen. Still, the explicit motivation for producing that representation

[issue3008] Let bin() show floats

2008-05-30 Thread Alexander Belopolsky
Alexander Belopolsky <[EMAIL PROTECTED]> added the comment: What would you say to adding float-capable bin/oct/hex (+ maybe tobase) to the math module? ___ Python tracker <[EMAIL PROTECTED]> __

[issue3008] Let bin() show floats

2008-05-30 Thread Alexander Belopolsky
Alexander Belopolsky <[EMAIL PROTECTED]> added the comment: On Fri, May 30, 2008 at 1:47 PM, Antoine Pitrou <[EMAIL PROTECTED]> wrote: .. > 1. while taking the binary representation of an integer has a real > meaning, taking the binary representation of a float only exposes an > implementation de

[issue3008] Let bin() show floats

2008-05-30 Thread Alexander Belopolsky
Alexander Belopolsky <[EMAIL PROTECTED]> added the comment: On Fri, May 30, 2008 at 1:47 PM, Antoine Pitrou <[EMAIL PROTECTED]> wrote: .. > 2. if two numbers (one integer and one float) are equal, it sounds > expectable that calling a function on them will produce similar output > (or fail). .. W

[issue3008] Let bin() show floats

2008-05-30 Thread Antoine Pitrou
Antoine Pitrou <[EMAIL PROTECTED]> added the comment: > I think you are mistaken. Python always distinguished between floats > and integers Sorry, my bad. > For example, if > bin is used inside f() only to produce some log output, but > otherwise f() works on any number, promiscuous bin() w

[issue3008] Let bin() show floats

2008-05-30 Thread Alexander Belopolsky
Alexander Belopolsky <[EMAIL PROTECTED]> added the comment: While writing my previous comments I did not realize that '%x' % accepts floats: >>> "%x" % 3.1415 '3' Float support has been even improved somewhat since 2.5: Python 2.5 (r25:51908, Nov 24 2006, 11:03:50) >>> '%x' % 1e10 Traceback (

[issue3008] Let bin() show floats

2008-05-30 Thread Alexander Belopolsky
Alexander Belopolsky <[EMAIL PROTECTED]> added the comment: On Fri, May 30, 2008 at 10:52 AM, Antoine Pitrou <[EMAIL PROTECTED]> wrote: > > Antoine Pitrou <[EMAIL PROTECTED]> added the comment: > > Well it's quite simple. Imagine you have a function f() which takes an > integer parameter named x,

[issue3008] Let bin() show floats

2008-05-30 Thread Antoine Pitrou
Antoine Pitrou <[EMAIL PROTECTED]> added the comment: Well it's quite simple. Imagine you have a function f() which takes an integer parameter named x, and somewhere applies bin() to this parameters. Right now, if you call f(1.0) instead of f(1), you will get a TypeError, which is easy to detect

[issue3008] Let bin() show floats

2008-05-30 Thread Alexander Belopolsky
Alexander Belopolsky <[EMAIL PROTECTED]> added the comment: I like the idea in general. It is way too common for people to be confused by decimal representation of floats, so an obvious mechanism to display the true value will be helpful. I don't think a promiscuous bin() will lead to obscure

[issue3008] Let bin() show floats

2008-05-30 Thread Antoine Pitrou
Antoine Pitrou <[EMAIL PROTECTED]> added the comment: Or, if you want to educate people at all cost, the TypeError raised by bin() when trying it on a float object could include in its message the binary representation of the float object "for edification". :-) __

[issue3008] Let bin() show floats

2008-05-30 Thread Antoine Pitrou
Antoine Pitrou <[EMAIL PROTECTED]> added the comment: I'm not sure about the educational value of letting obscure bugs creeping in when someone passes a float where an int is expected :-) Your vis() function looks appropriate for the task of educating people, why should its behaviour be folded in

[issue3008] Let bin() show floats

2008-05-30 Thread Raymond Hettinger
New submission from Raymond Hettinger <[EMAIL PROTECTED]>: Let bin() show floating point values. This would contribute quite a bit to people's understanding of floating point arithmetic. It has a nice education value and it makes it easier to diagnose floating point mysteries. def vis(f):