public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/44741] New: Complex division with NaN produces unexpected result
@ 2010-07-01 4:52 ian at airs dot com
2010-07-01 5:04 ` [Bug c/44741] " pinskia at gmail dot com
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: ian at airs dot com @ 2010-07-01 4:52 UTC (permalink / raw)
To: gcc-bugs
Annex G of the ISO C99 standard says that a complex value with one part being
infinity is considered an infinity, even if the other part is a NaN. It's not
clearly stated, but presumably if neither part of the number is an infinity,
but one part is a NaN, then the number is a NaN. And presumably if a complex
NaN is involved in a math operation, the result should be a complex NaN.
So, I would expect that dividing a complex NaN by a complex 0 would give me a
complex NaN. However, when I run this program:
#include <stdio.h>
#include <math.h>
#include <complex.h>
__complex float
div (__complex float f1, __complex float f2)
{
return f1 / f2;
}
int
main ()
{
__complex float f;
f = div (NAN + NAN * I, 0);
printf ("%g+%g*i\n", creal (f), cimag (f));
f = div (1.0 + NAN * I, 0);
printf ("%g+%g*i\n", creal (f), cimag (f));
f = div (NAN + 1.0 * I, 0);
printf ("%g+%g*i\n", creal (f), cimag (f));
}
with current mainline, it prints
nan+nan*i
nan+nan*i
nan+inf*i
That last answer seems incorrect according to the rules of Annex G. It is an
infinity when it should be a NaN.
--
Summary: Complex division with NaN produces unexpected result
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ian at airs dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44741
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Bug c/44741] New: Complex division with NaN produces unexpected result
2010-07-01 4:52 [Bug c/44741] New: Complex division with NaN produces unexpected result ian at airs dot com
2010-07-01 5:04 ` [Bug c/44741] " pinskia at gmail dot com
@ 2010-07-01 5:04 ` Andrew Pinski
2010-07-01 10:51 ` [Bug c/44741] " paolo dot carlini at oracle dot com
2010-07-02 0:36 ` pinskia at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: Andrew Pinski @ 2010-07-01 5:04 UTC (permalink / raw)
To: gcc-bugzilla; +Cc: gcc-bugs
I think the issue is we don't implement imagainy types so 1 + nan I
turns into nan.
On Jun 30, 2010, at 9:51 PM, "ian at airs dot com" <gcc-bugzilla@gcc.gnu.org
> wrote:
> Annex G of the ISO C99 standard says that a complex value with one
> part being
> infinity is considered an infinity, even if the other part is a
> NaN. It's not
> clearly stated, but presumably if neither part of the number is an
> infinity,
> but one part is a NaN, then the number is a NaN. And presumably if
> a complex
> NaN is involved in a math operation, the result should be a complex
> NaN.
>
> So, I would expect that dividing a complex NaN by a complex 0 would
> give me a
> complex NaN. However, when I run this program:
>
>
> #include <stdio.h>
> #include <math.h>
> #include <complex.h>
>
> __complex float
> div (__complex float f1, __complex float f2)
> {
> return f1 / f2;
> }
>
> int
> main ()
> {
> __complex float f;
>
> f = div (NAN + NAN * I, 0);
> printf ("%g+%g*i\n", creal (f), cimag (f));
> f = div (1.0 + NAN * I, 0);
> printf ("%g+%g*i\n", creal (f), cimag (f));
> f = div (NAN + 1.0 * I, 0);
> printf ("%g+%g*i\n", creal (f), cimag (f));
> }
>
> with current mainline, it prints
>
> nan+nan*i
> nan+nan*i
> nan+inf*i
>
> That last answer seems incorrect according to the rules of Annex G.
> It is an
> infinity when it should be a NaN.
>
>
> --
> Summary: Complex division with NaN produces unexpected
> result
> Product: gcc
> Version: 4.6.0
> Status: UNCONFIRMED
> Severity: normal
> Priority: P3
> Component: c
> AssignedTo: unassigned at gcc dot gnu dot org
> ReportedBy: ian at airs dot com
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44741
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/44741] Complex division with NaN produces unexpected result
2010-07-01 4:52 [Bug c/44741] New: Complex division with NaN produces unexpected result ian at airs dot com
@ 2010-07-01 5:04 ` pinskia at gmail dot com
2010-07-01 5:04 ` [Bug c/44741] New: " Andrew Pinski
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gmail dot com @ 2010-07-01 5:04 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gmail dot com 2010-07-01 05:04 -------
Subject: Re: New: Complex division with NaN produces unexpected result
I think the issue is we don't implement imagainy types so 1 + nan I
turns into nan.
On Jun 30, 2010, at 9:51 PM, "ian at airs dot com" <gcc-bugzilla@gcc.gnu.org
> wrote:
> Annex G of the ISO C99 standard says that a complex value with one
> part being
> infinity is considered an infinity, even if the other part is a
> NaN. It's not
> clearly stated, but presumably if neither part of the number is an
> infinity,
> but one part is a NaN, then the number is a NaN. And presumably if
> a complex
> NaN is involved in a math operation, the result should be a complex
> NaN.
>
> So, I would expect that dividing a complex NaN by a complex 0 would
> give me a
> complex NaN. However, when I run this program:
>
>
> #include <stdio.h>
> #include <math.h>
> #include <complex.h>
>
> __complex float
> div (__complex float f1, __complex float f2)
> {
> return f1 / f2;
> }
>
> int
> main ()
> {
> __complex float f;
>
> f = div (NAN + NAN * I, 0);
> printf ("%g+%g*i\n", creal (f), cimag (f));
> f = div (1.0 + NAN * I, 0);
> printf ("%g+%g*i\n", creal (f), cimag (f));
> f = div (NAN + 1.0 * I, 0);
> printf ("%g+%g*i\n", creal (f), cimag (f));
> }
>
> with current mainline, it prints
>
> nan+nan*i
> nan+nan*i
> nan+inf*i
>
> That last answer seems incorrect according to the rules of Annex G.
> It is an
> infinity when it should be a NaN.
>
>
> --
> Summary: Complex division with NaN produces unexpected
> result
> Product: gcc
> Version: 4.6.0
> Status: UNCONFIRMED
> Severity: normal
> Priority: P3
> Component: c
> AssignedTo: unassigned at gcc dot gnu dot org
> ReportedBy: ian at airs dot com
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44741
>
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44741
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/44741] Complex division with NaN produces unexpected result
2010-07-01 4:52 [Bug c/44741] New: Complex division with NaN produces unexpected result ian at airs dot com
2010-07-01 5:04 ` [Bug c/44741] " pinskia at gmail dot com
2010-07-01 5:04 ` [Bug c/44741] New: " Andrew Pinski
@ 2010-07-01 10:51 ` paolo dot carlini at oracle dot com
2010-07-02 0:36 ` pinskia at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-07-01 10:51 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from paolo dot carlini at oracle dot com 2010-07-01 10:51 -------
Note: a very similar issue probably affects C++.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44741
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/44741] Complex division with NaN produces unexpected result
2010-07-01 4:52 [Bug c/44741] New: Complex division with NaN produces unexpected result ian at airs dot com
` (2 preceding siblings ...)
2010-07-01 10:51 ` [Bug c/44741] " paolo dot carlini at oracle dot com
@ 2010-07-02 0:36 ` pinskia at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-07-02 0:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pinskia at gcc dot gnu dot org 2010-07-02 00:36 -------
1.0 + NAN * I is always (NaN, NaN) as we don't implement imaginary types. So
this is the correct value since we don't do those.
See http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1464.htm for ways of the C
standard committee fixing this issue with respect of creating complex values.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44741
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-07-02 0:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-01 4:52 [Bug c/44741] New: Complex division with NaN produces unexpected result ian at airs dot com
2010-07-01 5:04 ` [Bug c/44741] " pinskia at gmail dot com
2010-07-01 5:04 ` [Bug c/44741] New: " Andrew Pinski
2010-07-01 10:51 ` [Bug c/44741] " paolo dot carlini at oracle dot com
2010-07-02 0:36 ` pinskia at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).