Bug 111712 - trunc() and round() are broken
Summary: trunc() and round() are broken
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc (Show other bugs)
(Show other bugs)
Version: 1
Hardware: All Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-12-09 07:57 UTC by Aaron VanDevender
Modified: 2007-11-30 22:10 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2003-12-09 15:07:31 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
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 07:59 UTC, Aaron VanDevender
no flags Details

Description Aaron VanDevender 2003-12-09 07:57:46 UTC
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):
glibc-2.3.2-101.1

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
2.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 07:59:19 UTC
Created attachment 96416 [details]
C source file which demonstrates broken trunc() and round()

Comment 2 Miloslav Trmac 2003-12-09 15:00:30 UTC
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 15:07:31 UTC
s/-std=gnu9x/-std=gnu99/.  Other ways to make it work are also -D_GNU_SOURCE or
-D_ISOC99_SOURCE.
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.