[pythran] Re: cx-limited-range

  • From: serge Guelton <sguelton@xxxxxxxxxxxxx>
  • To: pythran@xxxxxxxxxxxxx
  • Date: Sun, 16 Nov 2014 12:18:51 +0100

On Fri, Nov 14, 2014 at 01:28:35PM -0800, Mehdi AMINI wrote:
> On 11/14/14, 1:23 PM, serge Guelton wrote:
> >On Fri, Nov 14, 2014 at 12:02:15PM -0800, Mehdi AMINI wrote:
> >>Hi,
> >>
> >>from pythran/pythonic/patch/README.rst
> >>"""
> >>The implementation of std::complex is very slow, due to the complex limited
> >>range (see `-fcx-limited-range`) feature. Numpy does not implement it, so we
> >>have to conform to numpy's version.
> >>"""
> >Let's focus on the multiplication.
> 
> Are you kidding, I explicitly linked the Python division implementation!

So let's focus on division:

from the numpy source (in ./numpy/core/src/umath/loops.c.src)


        if (in2r_abs >= in2i_abs) {
            if (in2r_abs == 0 && in2i_abs == 0) {
                /* divide by zero should yield a complex inf or nan */
                ((@ftype@ *)op1)[0] = in1r/in2r_abs;
                ((@ftype@ *)op1)[1] = in1i/in2i_abs;
            }
            else {
                const @ftype@ rat = in2i/in2r;
                const @ftype@ scl = 1.0@c@/(in2r + in2i*rat);
                ((@ftype@ *)op1)[0] = (in1r + in1i*rat)*scl;
                ((@ftype@ *)op1)[1] = (in1i - in1r*rat)*scl;
            }
        }
        else {
            const @ftype@ rat = in2r/in2i;
            const @ftype@ scl = 1.0@c@/(in2i + in2r*rat);
            ((@ftype@ *)op1)[0] = (in1r*rat + in1i)*scl;
            ((@ftype@ *)op1)[1] = (in1i*rat - in1r)*scl;
        }

So basically they don't care about IEEE. Quoting from CPython source:

    As usual, though, we're still ignoring all IEEE endcases.

I'll still propose a PR to update the README

Other related posts: