comp.lang.ada
 help / color / mirror / Atom feed
From: Jan Prazak <janp9@gmx.net>
Subject: gnat: float problem
Date: Sun, 07 Jul 2002 14:06:41 -0100
Date: 2002-07-07T14:06:41-01:00	[thread overview]
Message-ID: <pan.2002.07.07.14.03.50.890537.1744@gmx.net> (raw)

Hello,

I don't know if this is a bug or not, please take a look:

-----------------
with Text_IO; use Text_IO;

procedure my_test is
i : integer;
f : float := -1.0;
package My_int_io is new Integer_IO(integer); use My_int_io;
package My_float_io is new Float_IO(float); use My_float_io;
begin
    new_line;

    for x in 1 .. 6
    loop
        put(f);
        i := integer(f);
        put(i);
        new_line;
        f := f + 0.1;
    end loop;

    new_line;

    put(integer(-0.5)); -- prints "-1"
end;
----------------

OUTPUT:

-1.00000E+00         -1
-9.00000E-01         -1
-8.00000E-01         -1
-7.00000E-01         -1
-6.00000E-01         -1
-5.00000E-01          0

         -1

I know that floating point numbers are not very exact, but this really
looks like a bug, because -5.00000E-01 == -0.5.

Jan




             reply	other threads:[~2002-07-07 15:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-07 15:06 Jan Prazak [this message]
2002-07-07 14:08 ` float problem 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
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