Bug 441717 - Wrong results for calls to powf(float, float) in ansi-c
Wrong results for calls to powf(float, float) in ansi-c
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: glibc (Show other bugs)
5.3
i686 Linux
low Severity medium
: rc
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2008-04-09 12:53 EDT by Thomas Reiter
Modified: 2008-04-09 13:26 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2008-04-09 13:26:15 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


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

  None (edit)
Description Thomas Reiter 2008-04-09 12:53:58 EDT
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 12:53:58 EDT
Created attachment 301849 [details]
preprocessed C-file
Comment 2 Jakub Jelinek 2008-04-09 13:26:15 EDT
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.