This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Fix problem with peculiar ranges for a-nudira.adb


Ada.Numerics.Discrete_Random malfunctions if the instantiated type
requires 64-bits, but has dynamic bounds, or also if it has a large
negative bound and small positive bound. This patch fixes these
marginal cases.

A test program is:

with Ada.Numerics.Discrete_Random;
with Ada.Text_IO; use Ada.Text_IO;
procedure Randomd is
   type Item is mod 2 ** 32;

   function F return Item is
   begin return Item'Last; end;

   subtype Itemt is Item range 0 .. F;

   package IO is new Ada.Text_IO.Modular_IO(Itemt);
   package RNG is new Ada.Numerics.Discrete_Random(Itemt); use RNG;
   G : Generator;
   x : Item;

begin
   Put("Reset ...");
   Reset(G, 0);
   Put_Line(" done.");
   for i in 1..10 loop
      x := Random (G);
      New_Line;
      Put(Integer'Image(i) & ". x= ");
      IO.Put(x, Width=>12, Base=>16);
      New_Line;
   end loop;
end Randomd;

Before the patch, several entries gave the largest negative number,
which is clearly wrong. With the patch, we get the expected output:

Reset ... done.

 1. x= 16#4CE4B376#

 2. x= 16#6A34D860#

 3. x= 16#2FB905B5#

 4. x=  16#74F8D49#

 5. x= 16#AB860FBA#

 6. x= 16#6384A1C4#

 7. x= 16#9679E2F3#

 8. x= 16#93BE9059#

 9. x= 16#429AB850#

 10. x= 16#435B989D#

Tested on x86_64-pc-linux-gnu, committed on trunk

2009-06-19  Robert Dewar  <dewar@adacore.com>

	* a-nudira.adb (Need_64): Handle negative ranges and also dynamic
	ranges

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]