From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 19 Nov 91 00:23:10 GMT From: cochiti.lanl.gov!jlg@lanl.gov (Jim Giles) Subject: Re: Numeric problem with Ada Message-ID: <1991Nov19.002310.23171@beta.lanl.gov> List-Id: At least on the Sun/Sparc, C is compiled so that it _always_ uses double precision for intermediate calculations - no matter how explicitly you ask for just (float). main() { float z; int mz; mz = 7; z = 2.6 * mz - 0.2; if ( z == 18.0 ) printf ("%2.6f\n", z); } This program always prints `18.000000' even if mz is set in a separately compiled procedure. The reason is that the calculation in the assignment statement to `z' is always done in double and then rounded to float when the assignment is done. The same continues to be true even if the expression is altered to: z = (float) 2.6 * (float) mz - (float) 0.2; So, that's why C always gives 18.000000 on Sun/Sparc. I suspect the same may be true of other C implementations. J. Giles