Red Hat Bugzilla – Bug 111712
trunc() and round() are broken
Last modified: 2007-11-30 17:10:34 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):
always. i have tried this out on several machines with similar results.
Steps to Reproduce:
1.cc -lm broken.c -o broken.x
trunc(99.900000) = -1717986918.000000
round(-44.400000) = 858993459.000000
trunc(99.900000) = 99.000000
round(-44.400000) = -44.000000
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.
Created attachment 96416 [details]
C source file which demonstrates broken trunc() and round()
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.
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.