Bug 111712 - trunc() and round() are broken
trunc() and round() are broken
Product: Fedora
Classification: Fedora
Component: glibc (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2003-12-09 02:57 EST by Aaron VanDevender
Modified: 2007-11-30 17:10 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2003-12-09 10:07:31 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
C source file which demonstrates broken trunc() and round() (219 bytes, text/plain)
2003-12-09 02:59 EST, Aaron VanDevender
no flags Details

  None (edit)
Description Aaron VanDevender 2003-12-09 02:57:46 EST
Description of problem:
the trunc() and round() functions are broken in a pretty dramatic way.
I'll attach a C source file which demonstrates this.

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

How reproducible:
always. i have tried this out on several machines with similar results.

Steps to Reproduce:
1.cc -lm broken.c -o broken.x
Actual results:
trunc(99.900000) = -1717986918.000000
round(-44.400000) = 858993459.000000

Expected results:
trunc(99.900000) = 99.000000
round(-44.400000) = -44.000000

Additional info:
It looks like this has been broken for a while. I tried it out on a
RH7.3 box and also got bogus (although different) results.
Comment 1 Aaron VanDevender 2003-12-09 02:59:19 EST
Created attachment 96416 [details]
C source file which demonstrates broken trunc() and round()
Comment 2 Miloslav Trmac 2003-12-09 10:00:30 EST
You should use -Wall:
x.c:4: warning: return type defaults to `int'
x.c: In function `main':
x.c:6: warning: implicit declaration of function `trunc'
x.c:8: warning: implicit declaration of function `round'
x.c:11: warning: control reaches end of non-void function

It is necessary to pass -std=c99 or -std=gnu9x to gcc so that
trunc () and round () is properly declared.
Comment 3 Jakub Jelinek 2003-12-09 10:07:31 EST
s/-std=gnu9x/-std=gnu99/.  Other ways to make it work are also -D_GNU_SOURCE or
The reason why they are not prototyped for !ISO C99 compilations is
to avoid math.h namespace pollution where earlier standards require
what identifiers can be used in that header.
See info libc on Feature Test Macros.

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