Date: Sat, 19 Nov 1994 15:53:26 -0500 From: davis AT amy DOT tch DOT harvard DOT edu ("John E. Davis") To: turnbull AT shako DOT sk DOT tsukuba DOT ac DOT jp Subject: RE: printf or floating point error????? Cc: djgpp AT sun DOT soe DOT clarkson DOT edu, dolan AT fnoc DOT navy DOT mil, gordon AT spot DOT colorado DOT edu > Consider: > > float x, y; > long i = 10; > > /* assume sizeof (float) == sizeof (long) */ > > x = (float) i; > y = *(float *) &i; > > Here `x' will have the value of 10.0 whereas `y' has the bit > pattern that you re suggesting above. `y' will will almost > certainly not be 10.0 and `x' will not have the bit pattern of `i'. > That is, the float cast above will definitely modify the bit > pattern of i. > >This example is bogus because > > x = i; > >will work without the cast, and it means (in K&R C) > > x = (float) (double) i; Just because I used an explicit cast in the conversion of int to float does not make the example bogus. I think the example illustrates the point quite well, in fact, I believe that it would not be as effective without the cast. --John