public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/48738] New: pow() fails to produce (some) subnormalized numbers with integer exponents
@ 2011-04-23  7:22 paulo1205 at yahoo dot com
  2011-04-23  9:21 ` [Bug libstdc++/48738] " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: paulo1205 at yahoo dot com @ 2011-04-23  7:22 UTC (permalink / raw)
  To: gcc-bugs

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 <cmath>'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))'.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-05-25 12:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-23  7:22 [Bug libstdc++/48738] New: pow() fails to produce (some) subnormalized numbers with integer exponents paulo1205 at yahoo dot com
2011-04-23  9:21 ` [Bug libstdc++/48738] " rguenth at gcc dot gnu.org
2011-04-23 13:56 ` paulo1205 at yahoo dot com
2011-04-23 16:24 ` rguenth at gcc dot gnu.org
2011-04-23 20:27 ` paolo.carlini at oracle dot com
2011-05-25 10:17 ` [Bug tree-optimization/48738] " paolo.carlini at oracle dot com
2011-05-25 13:04 ` wschmidt at gcc dot gnu.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).