From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12473 invoked by alias); 23 Apr 2011 07:22:47 -0000 Received: (qmail 12457 invoked by uid 22791); 23 Apr 2011 07:22:45 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 23 Apr 2011 07:22:32 +0000 From: "paulo1205 at yahoo dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/48738] New: pow() fails to produce (some) subnormalized numbers with integer exponents X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: paulo1205 at yahoo dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Sat, 23 Apr 2011 07:22:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-04/txt/msg02404.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48738 Summary: pow() fails to produce (some) subnormalized numbers with integer exponents Product: gcc Version: 4.4.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: paulo1205@yahoo.com The standard 's function pow() fails to produce some sub-normalized numbers if the version that takes an integer exponent is used (using G++ 4.4.3, x86_64-linux-gnu). For example, the following piece of code will cause 'p' to get a zero value, instead of the expected sub-normalized value 5.56268464626e-309. double p=pow(2.0, -1024); I dug the include files to try to discover the reason for this strange result. It seemed to me that the function that gets called when the exponent is integer first checks if the exponent is negative, and calls yet another overloaded version that takes an unsigned exponent, passing to it the absolute value of the original exponent, and dividing 1.0 by the received result. So, apparently my original call 'pow(2.0, -1024)' became translated to '1.0/pow(2.0, 1024u)'. However, as 2**1024 is too large for a double, it becomes the positive infinity, and the result of dividing 1.0 by this infinity is zero. As a sanity check, I tried to make the exponent a double (i.e. I did double p=pow(2.0, -1024.0); instead). Not surprisingly, now I got 5.56268464626e-309, which was the result that I expected from the beginning with an integer exponent. POSSIBLE FIX: Maybe the fix is simple (yet I didn't work it to a very long extent): instead of making 'pow(some_double, some_negative_int)' become '1.0/pow(some_double, unsigned(-some_negative_int))', change it to 'pow(1.0/some_double, unsigned(-some_negative_int))'.