[Numpy-discussion] bug in oldnumeric.ma

Jonathan Wright wright@esrf...
Wed May 7 16:08:07 CDT 2008


Anne Archibald wrote:
> 2008/5/7 Pierre GM <pgmdevlist@gmail.com>:
>   
>> All,
>>  Yes, there is a problem with ma.power: masking negative data should be
>>  restricted to the case of an exponent between -1. and 1. only, don't you
>>  think ?
>>     
>
> No, there's a problem with any fractional exponent (with even
> denominator): x**(3/2) == (x**3)**(1/2). And of course in a
> floating-point world, you can't really ask whether the denominator is
> even or not. So any non-integer power is trouble.
>
> The draconian approach would be to simply disallow negative numbers to
> be raised to exponents of type float, but that's going to annoy a lot
> of people who have integers which happen to be represented in floats.
> (Representing integers in floats is exact up to some fairly large
> value.) So the first question is "how do we recognize floats with
> integer values?". Unfortunately that's not the real problem. The real
> problem is "how do we predict when power() is going to produce a NaN?"
>
> Anne
>   

Is there a rule against squaring away the negatives?

def not_your_normal_pow( x, y ): return exp( log( power( x, 2) ) * y / 2 )

Which still needs some work for x==0.

Jon


More information about the Numpy-discussion mailing list