![]() |
|
|
|
|
1
6th February 22:50
External User
Posts: 1
|
On 15 Jul 2003 19:33:07 -0700, dpnich@optushome.com.au (Dylan Nicholson)
First, this appears to be c++, not c, although the concepts are essentially the same in this case. VC6 supports C90, and not C99, so there are several compiler errors in the above. Second, set your compiler to conforming mode: /Za Disable Language Extensions (check box selected) ANSI C compatibility. Language constructs not compatible with ANSI C are flagged as errors. Note that this also turns on the /Op (Improve Float Consistency) flag, which is what is required here. With /Za set, neither "huh 1" nor "huh 2" is output, and there are no anomalies, and the behavior is conforming. However, without /Za set, VC will default to a mode where floating-point values remain in registers, and are not type-converted in all cases dictated by the standard. I got both "huh 1" and "huh 2" output, which is what I would expect, given VC's default behavior. Relative to your first post, it would appear that f is rounded up when converted from double to float, more than FLT_EPSILON. Note that 5.15002 has type double. Informally, what I see in the debugger is 5.1500201225281 = f (as double) 5.1500201192093 = d + FLT_EPSILON 5.1500200000000 = d so the result we get is consistent with what we see here. As another poster has suggested, you may want to look into the problems associated with floating-point representations. Regards, Bruce Wheeler |
|
|
|
|
|