comp.lang.ada
 help / color / mirror / Atom feed
From: "Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net>
Subject: Re: float problem
Date: Mon, 08 Jul 2002 18:19:08 GMT
Date: 2002-07-08T18:19:08+00:00	[thread overview]
Message-ID: <wIkW8.20430$5f3.9363@nwrddc01.gnilink.net> (raw)
In-Reply-To: pan.2002.07.07.17.55.32.704378.1959@gmx.net


> Thanks, I didn't know that procedure "put" rounds given number. I have
> just started to learn Ada, but I was using Pascal (and a bit Delphi)
> before, where there is no rounding in procedure "write".

Of course there is, as there is with the output of floating point numbers in
most languages. The internal representation of floating point numbers are
generally in binary format, whereas text output for humans should be in
decimal. To represent the exact value stored in the internal representation
would require dozens of decimal digits, most of which would be inaccurate
due to roundoff errors. In every programming language I know of, the default
is to display only as many decimal digits as can be expected to be accurate.
The number is rounded to this reasonable number of decimal digits.

For 32 bit IEEE floating numbers, one cannot guarantee that more than 6
decimal digits are accurate. That is why the default format for outputting
such numbers only displays 6 decimal digits (1 before the decimal point, 5
after the decimal point)

> BTW: is it possible to disable the rounding in "put"? Maybe with some
> global boolean variable or someting (maybe a pragma).

One way to see more decimal digits would be to increase the value of
My_Float_Io.Default_Aft, e.g.

    My_Float_Io.Default_Aft := 6;

This will change the default Aft for all calls to My_Float_Io.Put. As an
alternative, I would recommend that in the call to Put for f, specify the
AFT parameter and make it something larger than Float'Aft, e.g.

        put(f, Aft => 6);

When I did this in your test program, the problem is shown rather clearly:

-1.000000E+00         -1
-9.000000E-01         -1
-8.000000E-01         -1
-6.999999E-01         -1
-5.999999E-01         -1
-4.999999E-01          0

         -1





  parent reply	other threads:[~2002-07-08 18:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-07 15:06 gnat: float problem Jan Prazak
2002-07-07 14:08 ` Frank J. Lhota
2002-07-08 20:20   ` Jan Prazak
2002-07-08 18:10     ` David C. Hoos
2002-07-09  1:05       ` Robert A Duff
2002-07-09  2:14         ` David C. Hoos, Sr.
2002-07-08 18:19     ` Frank J. Lhota [this message]
2002-07-08 19:12     ` tmoran
2002-07-08 19:28     ` achrist
2002-07-08 23:00     ` Jan Prazak
2002-07-08 23:00     ` Jan Prazak
2002-07-08 20:34       ` David C. Hoos
2002-07-09 13:36       ` Ted Dennison
2002-07-09 19:03         ` Jeffrey Carter
2002-07-09 20:07         ` Robert Dewar
2002-07-07 21:04 ` gnat: " achrist
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox