[Python-Dev] Mixing float and Decimal -- thread reboot (original) (raw)

Adam Olsen rhamph at gmail.com
Fri Mar 26 00:10:56 CET 2010


On Thu, Mar 25, 2010 at 04:18, Steven D'Aprano <steve at pearwood.info> wrote:

def myfunc(x, y):  if x == y:  return 1.0  else:  return somethingcomplicated**(x-y)

Optimising floating point code is fraught with dangers (the above fails for x=y=INF as well as NAN) but anything that make Not A Numbers pretend to be numbers is a bad thing.

What about this:

def myfunc(x): if x >= THRESHOLD: return 1.0 else: return something_complicated(x)

If one behaves right it's more likely a fluke, not a designed in feature. It's certainly not obvious without covering every comparison with comments.

Maybe that's the solution. Signal by default on comparison, but add a collection of naneq/naneg/etc functions (math module, methods, whatever) that use a particular quiet mapping, making the whole thing explicit?

-- Adam Olsen, aka Rhamphoryncus



More information about the Python-Dev mailing list