public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: Daniel.Levine@jhuapl.edu
To: gcc-gnats@gcc.gnu.org
Subject: libstdc++/10689: pow(std::complex(0),1/3) returns (nan, nan) instead of 0.
Date: Thu, 08 May 2003 18:16:00 -0000	[thread overview]
Message-ID: <20030508180759.15269.qmail@sources.redhat.com> (raw)


>Number:         10689
>Category:       libstdc++
>Synopsis:       pow(std::complex(0),1/3) returns (nan, nan) instead of 0.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Thu May 08 18:16:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Daniel Levine
>Release:        gcc 3.2-7
>Organization:
>Environment:
Any.
>Description:
Executing the pow(0,y) function call for doubles correctly produces return values of 0 as long as y != 0.  Doing the same with the pow(std::complex<double>(0),y) will return (nan, nan).  This appears to be caused by the log(x) when x is 0 returning nan as it should.  Further exp() will never return 0 so some check needs to be implemented so pow(std::complex<double>(0),y) can return 0 when y != 0.

This problem is not specific to complex<double>.  Other complex floating point types would suffer from the same problem.

One final note, pow(std::complex<double>(0), 1) works because it triggers other code while pow(std::complex<double>(0), 1.0) fails.
>How-To-Repeat:
#include <iostream>
using namespace std;
complex<double> complexZero;
complex<double> cubeRootOf0 = pow(complexZero, 1.0/3.0);
cerr << cubeRootof0 << endl; // Should be 0.0;
complex<double> zeroToThe1.0 = pow(complexZero, 1.0);
cerr << zeroToThe1.0 << endl; // Should be 0.0;
complex<double> zeroToThe1 = pow(complexZero, 1);
cerr << zeroToThe1 << endl; // Is 0.0;
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2003-05-08 18:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-08 18:16 Daniel.Levine [this message]
2003-05-10 19:36 Dara Hazeghi
2003-05-16 20:04 bkoz
2003-05-18 13:06 Gabriel Dos Reis
2003-05-20  6:53 gdr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030508180759.15269.qmail@sources.redhat.com \
    --to=daniel.levine@jhuapl.edu \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).