bug? in gcc 4.8.1 complex acos

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

bug? in gcc 4.8.1 complex acos

Graeme
Works in Ubuntu, not in mingw. Used to works in earlier mingw but I've
upgraded, have lost the old version.

#include <stdio.h>
#include <complex.h>

int main() {
     double complex A;
     double complex a;
     A = 1.1;
     a = cacos( A ); // fails id abs(A) > 1.0
     printf("%.12g %.12g\n", creal(a), cimag(a) ); // prints '-1.#IND 0'
wrong
     a = cacos( 1.1 ); // calculated at compile time, OK
     printf("%.12g %.12g\n", creal(a), cimag(a) ); // prints '0
-0.443568254385' correct
     return 0;
}

in cmd prompt:
 >gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32
--build=mingw32 --without-pic --enable-shared --e
nable-static --with-gnu-ld --enable-lto --enable-libssp
--disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++
,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry
--enable-libstdcxx-debug --enable-version-specific
-runtime-libs --with-gmp=/usr/src/pkg/gmp-5.1.2-1-mingw32-src/bld
--with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --
with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes
--enable-libgomp --enable-threads --with-libiconv
-prefix=/mingw32 --with-libintl-prefix=/mingw --disable-bootstrap
LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)

 >ld -v
GNU ld (GNU Binutils) 2.24


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: bug? in gcc 4.8.1 complex acos

Keith Marshall
On 03/12/14 22:38, Graeme Paterson wrote:
> Works in Ubuntu, not in mingw.

Indeed, but it is *not* a GCC bug, (therefore not specific to any
version of GCC, as distributed by MinGW.org); it is actually a problem
in the complex *arcsine* function implementation in MinGW's runtime
library (mingwrt).

> Used to works in earlier mingw but I've upgraded, have lost the old
> version.

Really?  That surprises me.  The implementation was originally
contributed by Danny Smith, in October 2003, and there is no record of
it ever having been modified since.  In what version did you think it
might have worked?

> #include <stdio.h>
> #include <complex.h>
>
> int main() {
>   double complex A;
>   double complex a;
>   A = 1.1;
>   a = cacos( A ); // fails id abs(A) > 1.0

Indeed, this is where it first appears to go wrong, but it's actually in
casin(A), (which is called by cacos(A)), that the failure occurs.  In
the source, I see:

  double complex casin (double complex Z)
  {
    double complex Res;
    double x, y;

    x = __real__ Z;
    y = __imag__ Z;

    if (y == 0.0)
    {
      __real__ Res = asin (x);
      __imag__ Res = 0.0;
    }
    else
     :

which seems to be a sensible optimization, until you consider that
values of complex sine may lie outside the valid bounds for the real
asin(x) function; that's precisely what's happening in your case, and
asin(x) is correctly returning NaN, given the out-of-bounds argument.

>   printf("%.12g %.12g\n", creal(a), cimag(a) );
>     // prints '-1.#IND 0'  wrong
>   a = cacos( 1.1 ); // calculated at compile time, OK
>   printf("%.12g %.12g\n", creal(a), cimag(a) );
>     // prints '0  -0.443568254385' correct
>   return 0;
> }

Simply changing the `if (y == 0.0)', to also reject the optimization for
`fabs(x) > 1.0' is almost, but not quite, enough to get me to the
"correct" result you expect ... when performing the computation, the
casin(Z) function is returning an imaginary part with opposite sign to
that which might be expected, and this propagates in the result which is
returned by cacos(Z).  I guess a formal review of the entire complex
math suite in mingwrt, by an expert mathematician would be useful.

Any volunteers?

--
Regards,
Keith.

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: bug? in gcc 4.8.1 complex acos

Graeme
I must have been mistaken about it working previously. Can't imagine how.
On 12/4/2014 7:30 AM, Keith Marshall wrote:

> On 03/12/14 22:38, Graeme Paterson wrote:
>> Works in Ubuntu, not in mingw.
> Indeed, but it is *not* a GCC bug, (therefore not specific to any
> version of GCC, as distributed by MinGW.org); it is actually a problem
> in the complex *arcsine* function implementation in MinGW's runtime
> library (mingwrt).
>
>> Used to works in earlier mingw but I've upgraded, have lost the old
>> version.
> Really?  That surprises me.  The implementation was originally
> contributed by Danny Smith, in October 2003, and there is no record of
> it ever having been modified since.  In what version did you think it
> might have worked?
>
>> #include <stdio.h>
>> #include <complex.h>
>>
>> int main() {
>>    double complex A;
>>    double complex a;
>>    A = 1.1;
>>    a = cacos( A ); // fails id abs(A) > 1.0
> Indeed, this is where it first appears to go wrong, but it's actually in
> casin(A), (which is called by cacos(A)), that the failure occurs.  In
> the source, I see:
>
>    double complex casin (double complex Z)
>    {
>      double complex Res;
>      double x, y;
>
>      x = __real__ Z;
>      y = __imag__ Z;
>
>      if (y == 0.0)
>      {
>        __real__ Res = asin (x);
>        __imag__ Res = 0.0;
>      }
>      else
>       :
>
> which seems to be a sensible optimization, until you consider that
> values of complex sine may lie outside the valid bounds for the real
> asin(x) function; that's precisely what's happening in your case, and
> asin(x) is correctly returning NaN, given the out-of-bounds argument.
>
>>    printf("%.12g %.12g\n", creal(a), cimag(a) );
>>      // prints '-1.#IND 0'  wrong
>>    a = cacos( 1.1 ); // calculated at compile time, OK
>>    printf("%.12g %.12g\n", creal(a), cimag(a) );
>>      // prints '0  -0.443568254385' correct
>>    return 0;
>> }
> Simply changing the `if (y == 0.0)', to also reject the optimization for
> `fabs(x) > 1.0' is almost, but not quite, enough to get me to the
> "correct" result you expect ... when performing the computation, the
> casin(Z) function is returning an imaginary part with opposite sign to
> that which might be expected, and this propagates in the result which is
> returned by cacos(Z).  I guess a formal review of the entire complex
> math suite in mingwrt, by an expert mathematician would be useful.
>
> Any volunteers?
>


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: bug? in gcc 4.8.1 complex acos

Keith Marshall
In reply to this post by Keith Marshall
On 04/12/14 14:30, Keith Marshall wrote:
> On 03/12/14 22:38, Graeme Paterson wrote:
>> Works in Ubuntu, not in mingw.
   :

>> #include <stdio.h>
>> #include <complex.h>
>>
>> int main() {
>>   double complex A;
>>   double complex a;
>>   A = 1.1;
>>   a = cacos( A ); // fails id abs(A) > 1.0
>
> Indeed, this is where it first appears to go wrong, but it's actually in
> casin(A), (which is called by cacos(A)), that the failure occurs.

I've filed this bug report:
https://sourceforge.net/p/mingw/bugs/2245/

--
Regards,
Keith.

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: bug? in gcc 4.8.1 complex acos

Keith Marshall
On 09/12/14 20:10, Keith Marshall wrote:

> On 04/12/14 14:30, Keith Marshall wrote:
>> On 03/12/14 22:38, Graeme Paterson wrote:
>>> Works in Ubuntu, not in mingw.
>    :
>>> #include <stdio.h>
>>> #include <complex.h>
>>>
>>> int main() {
>>>   double complex A;
>>>   double complex a;
>>>   A = 1.1;
>>>   a = cacos( A ); // fails id abs(A) > 1.0
>>
>> Indeed, this is where it first appears to go wrong, but it's actually in
>> casin(A), (which is called by cacos(A)), that the failure occurs.
>
> I've filed this bug report:
> https://sourceforge.net/p/mingw/bugs/2245/

This is fixed, (together with a further bug in csqrt(), which came to
light while investigating this), in recently released mingwrt-3.21

--
Regards,
Keith.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe