Re: Next float?

2007-11-23 Thread Hendrik van Rooyen
Steven D'Aprano steve..IS.cybersource.com.au wrote: Damn, I don't remember writing that! It is caused by drinking too much Alzheimer's Light. : - ) - Hendrik -- http://mail.python.org/mailman/listinfo/python-list

Re: Next float?

2007-11-22 Thread Fredrik Johansson
On Nov 22, 2007 4:04 AM, Steven D'Aprano [EMAIL PROTECTED] wrote: Is there a simple, elegant way in Python to get the next float from a given one? By next float, I mean given a float x, I want the smallest float larger than x. Bonus points if I can go in either direction (i.e. the previous

Re: Next float?

2007-11-22 Thread Mark Dickinson
On Nov 22, 5:41 pm, Mark Dickinson [EMAIL PROTECTED] wrote: On Nov 21, 11:48 pm, Mark T [EMAIL PROTECTED] wrote: Here's some functions to get the binary representation of a float. Then just manipulate the bits (an exercise for the reader): import struct def f2b(f): return

Re: Next float?

2007-11-22 Thread Mark Dickinson
On Nov 21, 11:48 pm, Mark T [EMAIL PROTECTED] wrote: Here's some functions to get the binary representation of a float. Then just manipulate the bits (an exercise for the reader): import struct def f2b(f): return struct.unpack('I',struct.pack('f',f))[0] def b2f(b): return

Next float?

2007-11-21 Thread Steven D'Aprano
Is there a simple, elegant way in Python to get the next float from a given one? By next float, I mean given a float x, I want the smallest float larger than x. Bonus points if I can go in either direction (i.e. the previous float as well as the next). Note to maths pedants: I am aware

Re: Next float?

2007-11-21 Thread Alex Holkner
On Nov 22, 2007 2:04 PM, Steven D'Aprano [EMAIL PROTECTED] wrote: Is there a simple, elegant way in Python to get the next float from a given one? By next float, I mean given a float x, I want the smallest float larger than x. Bonus points if I can go in either direction (i.e. the previous

Re: Next float?

2007-11-21 Thread Mark T
Steven D'Aprano [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Is there a simple, elegant way in Python to get the next float from a given one? By next float, I mean given a float x, I want the smallest float larger than x. Bonus points if I can go in either direction (i.e

Re: Next float?

2007-11-21 Thread Robert Kern
Steven D'Aprano wrote: Is there a simple, elegant way in Python to get the next float from a given one? By next float, I mean given a float x, I want the smallest float larger than x. Courtesy of Tim Peters: http://mail.python.org/pipermail/python-list/2001-August/099152.html Bonus

Re: Next float?

2007-11-21 Thread Paul Rubin
Steven D'Aprano [EMAIL PROTECTED] writes: Is there a simple, elegant way in Python to get the next float from a given one? By next float, I mean given a float x, I want the smallest float larger than x. I think you have to do it by bit twiddling. But something like bisection search could

Re: Next float?

2007-11-21 Thread Robert Kern
Steven D'Aprano wrote: Is there a simple, elegant way in Python to get the next float from a given one? By next float, I mean given a float x, I want the smallest float larger than x. Heh: http://mail.python.org/pipermail/python-list/2005-December/357771.html -- Robert Kern I have come

Re: Next float?

2007-11-21 Thread Steven D'Aprano
On Thu, 22 Nov 2007 00:44:34 -0600, Robert Kern wrote: Steven D'Aprano wrote: Is there a simple, elegant way in Python to get the next float from a given one? By next float, I mean given a float x, I want the smallest float larger than x. Heh: http://mail.python.org/pipermail/python