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,MSGID_SHORT autolearn=no autolearn_force=no version=3.4.5-pre1 Date: 14 Nov 91 09:53:45 GMT From: mcsun!hp4nl!cwi.nl!jankok@uunet.uu.net (Jan Kok) Subject: Re: Numeric problem with Ada Message-ID: <4684@charon.cwi.nl> List-Id: In article <9111131948.AA20227@cnam.cnam.fr> bortz@CNAM.CNAM.FR writes: SB> ... SB>procedure TEST is SB> Mz : integer := 7; SB> Z2 : float; SB> package FLOAT_TEXT_IO is new TEXT_IO.FLOAT_IO (float); SB>begin SB> Z2 := 2.6 * float (Mz) - 0.2; SB> FLOAT_TEXT_IO.PUT (Z2, Aft => 6, Exp => 0); SB>end TEST; SB> SB>The program displays 17.999998 (the mathematical result is 18). ... SB> SB>main () SB>{ SB> int mz = 7; SB> float z2; SB> z2 = 2.6 * mz - 0.2; SB> printf ("%2.6f\n", z2); SB>} SB> SB>displays 18.000000. SB> SB>Stephane Bortzmeyer Conservatoire National des Arts et Metiers Dear Stephane, The answer with the Ada program is correct. You might accept this, but I suppose you want to understand the phenomenon. You did not say that the internal representations of the results with the two programs are different (I suppose they are not). Could you try something like: Z2 := float (18); FLOAT_TEXT_IO.PUT (Z2, Aft => 6, Exp => 0); I am suggesting this, because the explanation might be in the PUT procedure. Conversion from internal (binary) floating-point value to a decimal character string of finite length requires a sophisticated algorithm, and we certainly know about Ada I/O implementations that do not recognise all exact decimal values. Then, while computing successive decimal digits for the output string, some accuracy can get lost. I can also offer you an explanation in the case that the internal values of the Ada and C results are different, but then I would assume that the Ada PUT procedure would show a larger difference from 18. --Jan Kok. -- Mail: Jan Kok, CWI (afd. NW), Postbus 4079, NL-1009 AB Amsterdam, Nederland Net : jankok@cwi.nl --------------------------------------------------------------- Why is a computer?