comp.lang.ada
 help / color / mirror / Atom feed
* modular arithmetic bug in gnat?
@ 2000-02-09  0:00 David Shochat
  2000-02-09  0:00 ` tmoran
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: David Shochat @ 2000-02-09  0:00 UTC (permalink / raw)


The following test is the result of distilling an issue that came up at
work:

with Ada.Text_Io;

procedure Mod_Test is

    type M_2_16 is mod 2 ** 16;

    K : M_2_16 := 11_111;

    A : constant Integer :=
       Integer(K * 1000 / 25);
begin
    Ada.Text_Io.Put ("A = " & Integer'Image(A));
end Mod_Test;

When I run this with gnat (3.12p, Linux) the answer is 51224. This is
evidently the result of delaying the reduction mod 2**16 until after the
division.

The same program on Rational Apex (3.2.0b, HP-UX 11.0) gives 1416 which
is what you get if you reduce mod 2**16 immediately after the
multiplication but before the division.

Now based on 4.5(13), the result should be as if the operations were
performed left to right, i.e. multiplication followed by division. But
each of those operations must be as defined for the modular type, and
4.5.5(10) implies that the first operation is defined as including a
reduction. So the correct result must be

((11111 * 1000) mod 2**16) / 25, i.e. 1416.

Do you agree?

-- David






^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: modular arithmetic bug in gnat?
  2000-02-09  0:00 modular arithmetic bug in gnat? David Shochat
@ 2000-02-09  0:00 ` tmoran
  2000-02-09  0:00 ` reason67
  2000-02-16  0:00 ` Nick Roberts
  2 siblings, 0 replies; 4+ messages in thread
From: tmoran @ 2000-02-09  0:00 UTC (permalink / raw)


> So the correct result must be
> ((11111 * 1000) mod 2**16) / 25, i.e. 1416.
> Do you agree?
Yes, and so do two other, unrelated, Ada compilers.
Sounds like bug report time.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: modular arithmetic bug in gnat?
  2000-02-09  0:00 modular arithmetic bug in gnat? David Shochat
  2000-02-09  0:00 ` tmoran
@ 2000-02-09  0:00 ` reason67
  2000-02-16  0:00 ` Nick Roberts
  2 siblings, 0 replies; 4+ messages in thread
From: reason67 @ 2000-02-09  0:00 UTC (permalink / raw)


In article <38A144A0.141EA33F@chelmsford.com>,
  David Shochat <shochat@chelmsford.com> wrote:

> The same program on Rational Apex (3.2.0b, HP-UX 11.0) gives 1416
which
> is what you get if you reduce mod 2**16 immediately after the
> multiplication but before the division.
>
> Do you agree?

Have you tried recompiling it with no optimization to see if you get the
expected results?
---
Jeffrey Blatt


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: modular arithmetic bug in gnat?
  2000-02-09  0:00 modular arithmetic bug in gnat? David Shochat
  2000-02-09  0:00 ` tmoran
  2000-02-09  0:00 ` reason67
@ 2000-02-16  0:00 ` Nick Roberts
  2 siblings, 0 replies; 4+ messages in thread
From: Nick Roberts @ 2000-02-16  0:00 UTC (permalink / raw)


Yes, I certainly agree. GNAT bug, I think.

--
Nick Roberts
http://www.adapower.com/lab/adaos








^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-02-16  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-09  0:00 modular arithmetic bug in gnat? David Shochat
2000-02-09  0:00 ` tmoran
2000-02-09  0:00 ` reason67
2000-02-16  0:00 ` Nick Roberts

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