From: SourceForge.net <no...@so...> - 2007-10-21 10:27:06
|
Bugs item #1816470, was opened at 2007-10-19 13:49 Message generated for change (Comment added) made by maartenbrock You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1816470&group_id=599 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: C-Front End Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Stas Sergeev (stsp) >Assigned to: Maarten Brock (maartenbrock) Summary: miscalculation of literals Initial Comment: Hi. It seems sdcc is bad on calculating the literals. The following program (attached) returns 0xf4 on sdcc, and 0xf3 on gcc. --- int main() { return (unsigned char)(0x100 - 4000000 / 307200.0 + .5); } --- ---------------------------------------------------------------------- >Comment By: Maarten Brock (maartenbrock) Date: 2007-10-21 12:27 Message: Logged In: YES user_id=888171 Originator: NO I also thought in that direction, but 0.5 on 256 is too large an error for the mantissa to be the culprit. I turns out that SDCC inserted a cast to unsigned char before 0x100 turning it into 0. This is ok if both operands are integer types but not when one is a float. ---------------------------------------------------------------------- Comment By: Stas Sergeev (stsp) Date: 2007-10-19 16:38 Message: Logged In: YES user_id=501371 Originator: YES Very unlikely because the actual result of that calculation is 243.48, which is not even above 243.5. While 0xf4==244. Such a huge errors are clearly unacceptable and have nothing to do with the limited precision. Also note that there were no run-time calculations, no code dealing with floats was generated by sdcc. That expression is evaluated entirely compile-time. So the sizeof(float) that applies, is the one the sdcc was compiled with. And since it was compiled by gcc... ---------------------------------------------------------------------- Comment By: Patryk (patryks) Date: 2007-10-19 16:15 Message: Logged In: YES user_id=1788180 Originator: NO Maybe differences in floating point precision between SDCC and gcc? I mean target's sizeof(float). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=1816470&group_id=599 |