From: CNAM.CNAM.FR!bortz@ucbvax.Berkeley.EDU
Subject: Numeric problem with Ada
Date: 13 Nov 91 19:48:39 GMT [thread overview]
Message-ID: <9111131948.AA20227@cnam.cnam.fr> (raw)
(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
next reply other threads:[~1991-11-13 19:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1991-11-13 19:48 CNAM.CNAM.FR!bortz [this message]
-- strict thread matches above, loose matches on Subject: below --
1991-11-14 9:53 Numeric problem with Ada Jan Kok
1991-11-19 0:23 Jim Giles
1991-11-19 14:05 Jean-Pierre Rosen
1991-11-19 18:30 psinntp!vitro.com!v7.vitro.com!vaxs09
1991-11-21 8:57 Thomas Buenermann
1991-11-27 16:19 CNAM.CNAM.FR!bortz
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox