[Numpy-discussion] old-Numeric: OverflowError on exp(-760) (original) (raw)

Sasha ndarray at mac.com
Mon Jun 12 18:19:19 EDT 2006


BTW, here is the relevant explanation from mathmodule.c:

    /* ANSI C generally requires libm functions to set ERANGE
     * on overflow, but also generally *allows* them to set
     * ERANGE on underflow too.  There's no consistency about
     * the latter across platforms.
     * Alas, C99 never requires that errno be set.
     * Here we suppress the underflow errors (libm functions
     * should return a zero on underflow, and +- HUGE_VAL on
     * overflow, so testing the result for zero suffices to
     * distinguish the cases).
     */

On 6/12/06, Sasha <ndarray at mac.com> wrote:

I don't know about numarray, but the difference between Numeric and python math module stems from the fact that the math module ignores errno set by C library and only checks for infinity. Numeric relies on errno exclusively, numpy ignores errors by default:

>>> import numpy,math,Numeric >>> numpy.exp(-760) 0.0 >>> math.exp(-760) 0.0 >>> Numeric.exp(-760) Traceback (most recent call last): File "", line 1, in ? OverflowError: math range error >>> numpy.exp(760) inf >>> math.exp(760) Traceback (most recent call last): File "", line 1, in ? OverflowError: math range error >>> Numeric.exp(760) Traceback (most recent call last): File "", line 1, in ? OverflowError: math range error I would say it's a bug in Numeric, so you are out of luck. Unfortunalely, even MA.exp(-760) does not work, but this is easy to fix: >>> exp = MA.maskedunaryoperation(Numeric.exp,0.0,MA.domaincheckinterval(-100,100)) >>> exp(-760).filled() 0 You would need to replace -100,100 with the bounds appropriate for your system.

On 6/12/06, Sebastian Haase <haase at msg.ucsf.edu> wrote: > Hi, > I'm using Konrad Hinsen's LeastSquares.leastSquaresFit for a convenient way to > do a non linear minimization. It uses the "old" Numeric module. > But since I upgraded to Numeric 24.2 I get OverflowErrors that I tracked down > to > >>> Numeric.exp(-760.) > Traceback (most recent call last): > File "", line 1, in ? > OverflowError: math range error > > >From numarray I'm used to getting this: > >>> na.exp(-760) > 0.0 > > Mostly I'm confused because my code worked before I upgraded to version 24.2. > > Thanks for any hints on how I could revive my code... > -Sebastian Haase > > _> ________________________ > Numpy-discussion mailing list > Numpy-discussion at lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/numpy-discussion >



More information about the NumPy-Discussion mailing list