[Python-Dev] RE: [Numpy-discussion] RE: Possible bug (was Re: numpy, overflow, inf, ieee, and rich comparison)

Jeff Petkau jpet at eskimo.com
Sat Oct 14 03:37:47 EDT 2000


Huaiyu Zhu <hzhu at yahoo.com> wrote in message
news:slrn8uck1s.4id.hzhu at localhost.localdomain...
> On Thu, 12 Oct 2000 19:24:18 +0200, hinsen at dirac.cnrs-orleans.fr
> <hinsen at dirac.cnrs-orleans.fr> wrote:
> >
> >So how about making this a run-time option? I'd choose exceptions by
> >default and Infs and Nans by specifying a command-line option, but
> >there are certainly others who would prefer it the other way round.
> >What matters most to me is that the choice is possible somehow.
>
> So there is complete harmony here from number-crunchers. :-)
> Here's just a little thought about how that might be done:
>
> In mathmodule.c define math_1_check, math_1_nocheck, math_2_check, and
> math_2_nocheck.  Let math_1=math_1_check as default, if you will.

I really like this idea--it allows the caller to specify the behavior they
want,
without the trouble you get by dynamically setting FP modes.

It would be nice to be able to set rounding modes too, of course, but this
makes for an explosion of math modules. Maybe there's some way to
parameterize it?

import math

math2 = math.withfpu(rounding=math.round_to_nearest,
precision=math.double_precision,interrupt=0)
math3 = math2.withfpu(interrupt=math.em_overflow)

math.exp(800)
--> exception or not, whatever Guido likes

math2.exp(800)
--> INF

math3.exp(800)
--> exception

This wouldn't work with operators, so you couldn't control 1/0. But
at least you could control math.divide(1,0).

[Dynamically setting FPU modes (rounding, exceptions, whatever)
always seemed silly to me. Everyone learned twenty years ago that
lexical scoping is a Good Thing, but the lowest-level numeric
functions still change their behavior based on some global variables.
Argh. I think I'll blame Intel.]

--Jeff






More information about the Python-list mailing list