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: 13 Nov 91 19:48:39 GMT From: CNAM.CNAM.FR!bortz@ucbvax.Berkeley.EDU Subject: Numeric problem with Ada Message-ID: <9111131948.AA20227@cnam.cnam.fr> List-Id: (It seems that my first attempt to post this was a failure. I repost. Sorry if you receive it twice.) Hello, numeric addicts, I've a strange problem with numeric expressions in Ada. The test program (the original one was a calendar) is: procedure TEST is Mz : integer := 7; Z2 : float; package FLOAT_TEXT_IO is new TEXT_IO.FLOAT_IO (float); begin Z2 := 2.6 * float (Mz) - 0.2; FLOAT_TEXT_IO.PUT (Z2, Aft => 6, Exp => 0); end TEST; The program displays 17.999998 (the mathematical result is 18). I understand that, since float'DIGITS is 6 on all the machines I used (Vax/VMS and Sun3), I cannot expect the rightmost digit (the 8th) to be correct. If I declare my own floating-point type with 15 digits, I can have my result (18) fine. But my problem comes from the fact that the C compilers don't behave this way. The program: main () { int mz = 7; float z2; z2 = 2.6 * mz - 0.2; printf ("%2.6f\n", z2); } displays 18.000000. This is true also on both the Vax and the Sun3. Now the problem is: where does the difference comes from? I've checked the assembly code produced and the two programs use the same types (I was thinking that C was using the double-precision multiplication, but it's not the case). I'm not sure the code s are equivalent (it's too difficult for me to read assembly language), but I think they should. Is there something in the Ada floating-point model that prevents the Ada compiler to give better results? Stephane Bortzmeyer Conservatoire National des Arts et Metiers bortzmeyer@vcnam.cnam.fr Laboratoire d'Informatique bortz@cnam.cnam.fr 292, rue Saint-Martin 75141 Paris Cedex 03 France "C'est la nuit qu'il est beau de croire a la lumiere." E. Rostand