Bug 441717 - Wrong results for calls to powf(float, float) in ansi-c
Summary: Wrong results for calls to powf(float, float) in ansi-c
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: glibc
Version: 5.3
Hardware: i686
OS: Linux
low
medium
Target Milestone: rc
: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2008-04-09 16:53 UTC by Thomas Reiter
Modified: 2008-04-09 17:26 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2008-04-09 17:26:15 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
preprocessed C-file (19.08 KB, text/plain)
2008-04-09 16:53 UTC, Thomas Reiter
no flags Details

Description Thomas Reiter 2008-04-09 16:53:58 UTC
Description of problem:

C-programs using the float powf(float, float) function show a behaviour which is
not conform to Ansi-C.

Version-Release number of selected component (if applicable):

$gcc -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-9)

$rpm -qi glibc-headers
Name        : glibc-headers                Relocations: (not relocatable)
Version     : 2.3.4                             Vendor: Red Hat, Inc.
Release     : 2.39                          Build Date: Wed 12 Sep 2007 18:44:19 BST
Install Date: Fri 16 Nov 2007 03:23:04 GMT      Build Host:
ls20-bc1-14.build.redhat.com
Group       : Development/Libraries         Source RPM: glibc-2.3.4-2.39.src.rpm
...

How reproducible:

---- bogus.c -----
#include <math.h>
#include <stdio.h>

/* float powf(float, float); */

int main(int argc, char** argv) {
        float x = powf(2.0f, 3.0f);

        printf("%f\n", x);
        return 0;
}
----- EOF --------

Steps to Reproduce:
1. gcc -save-temps -o bogus -ansi bogus.c -lm
2. ./bogus

Actual results:
0.000000

Expected results:
8.000000

Additional info:

If the line /* float powf(float, float); */ is uncommented, the expected result
is reproduced.

Comment 1 Thomas Reiter 2008-04-09 16:53:58 UTC
Created attachment 301849 [details]
preprocessed C-file

Comment 2 Jakub Jelinek 2008-04-09 17:26:15 UTC
That's a user error, not library bug.
powf function isn't ISO C90, only in ISO C99 (and XPG6).
The -ansi switch is equivalent to -std=c89, requesting strict ISO C90 mode. 
<math.h> is an ISO C90 standard covered header, and as such powf doesn't belong
to it.  You need -std=c99 switch to request ISO C99 namespace instead (or
-std=gnu99), or use one of the appropriate feature test macros - in this case e.g.
-D_ISOC99_SOURCE, -D_XOPEN_SOURCE=600 or -D_GNU_SOURCE.  See
info libc 'Feature Test Macros'
or
info gcc
and search for C Dialect Options.


Note You need to log in before you can comment on or make changes to this bug.