From: SourceForge.net <no...@so...> - 2004-03-29 09:02:11
|
Bugs item #925099, was opened at 2004-03-29 11:15 Message generated for change (Comment added) made by dannysmith You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=925099&group_id=2435 Category: gcc Group: None >Status: Closed >Resolution: Fixed Priority: 5 Submitted By: RK (richardkaiser) Assigned to: Danny Smith (dannysmith) Summary: round error Initial Comment: With the C99 math.h round function cout<<"round: "<<round(3.64)<<endl; cout<<"round: "<<round(3.14)<<endl; cout<<"round: "<<round(-3.14)<<endl; cout<<"round: "<<round(-3.64)<<endl; I get the results 4 4 -4 -4. According to C99 (7.12.9.6) I would expect halfway cases rounded away from zero. Richard ---------------------------------------------------------------------- >Comment By: Danny Smith (dannysmith) Date: 2004-03-29 20:28 Message: Logged In: YES user_id=11494 Thanks for the report. You are right, it should usually round to nearest, but not use the even-odd rule that FE_TONEAREST uses for 'halfway' values. I've fixed in cvs. round() now does this: double round (double x) { /* Add +/- 0.5 then then round towards zero. */ return trunc ( x + (x >= 0.0 ? 0.5 : -0.5)); } ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=925099&group_id=2435 |