comp.lang.ada
 help / color / mirror / Atom feed
From: rracine@draper.com (Roger Racine)
Subject: Re: discriminant
Date: 1999/07/12
Date: 1999-07-12T00:00:00+00:00	[thread overview]
Message-ID: <rracine.21.0008309A@draper.com> (raw)
In-Reply-To: 3789bfc2.97977684@news.dsuper.net

In article <3789bfc2.97977684@news.dsuper.net> fluffy_doo@dsuper.net writes:
>I'm having problems with the use of a discriminant for a RECORD
>that is meant to hold the value for a High Precision Real Number
>(my own type defined in an ADT).  I did *not* get any compilation
>time errors for any of the things I have done (described below).

>In my .ADS I have the following private structure:

>PRIVATE
>  TYPE T_Sign_Temp IS (POSITIVE, NEGATIVE, ABSENT);
>  SUBTYPE T_Sign IS T_Sign_Temp RANGE POSITIVE..NEGATIVE;

>  SUBTYPE T_Digit IS integer RANGE 0..9;
>  TYPE T_Mantissa IS ARRAY (1..MAX_MANT_200) OF T_Digit;
>  SUBTYPE T_Len_Mantissa IS positive RANGE 1..MAX_SIG_FIG_30;

>  SUBTYPE T_Power IS integer RANGE integer'first..integer'last;
>  SUBTYPE T_Positive_Power IS T_Power RANGE 0..integer'last;

>  TYPE T_Kind IS ( INT, REAL, NONE );

>  TYPE T_Number ( kind : T_Kind := NONE ) IS
>  RECORD
>        Sign : T_Sign := POSITIVE;
>        Mant : T_Mantisse := (OTHERS => 0);
>        Len : T_Lng_Mantisse := 0;
>        CASE kind IS
>                WHEN REAL =>    Point : natural RANGE 0..MAX_SIG_FIG_30 := 1;
>                                                Power_R : T_Power := 0;
>                WHEN INT =>             Power_I : T_Positive_Power := 0;
>                WHEN NONE =>    NULL;
>                END CASE;
>  END RECORD;

>When I assign a value to the Power_R for a real numbrer, the "Point"
>field also changes (mysteriously), and after it has changed I can no 
>longer assign a new value to it.  On top of this, the new value that
>"Point" takes is *outside* my subtype range and no exception is
>raised !  It tends to take a value a bit over 500, while its top limit
>is a constant with a value of 30 !?!?  I got the value and the
>moment of the change occuring from the debugger.

I had to make a couple of changes to your source to get it to compile without 
warnings or errors.  Specifically, note that the spelling of "mantissa" is not 
consistent.  I assume those were typos in your message.  When I corrected 
those, I got a warning about Len raising Constraint_Error (it is assigned a 
value of 0, which is outside its range), so I changed it to have an initial 
value of 1.  After that, I created a test, which worked fine on the latest 
GNAT (3.12a) on Windows NT.

What version of what compiler are you using on what host?
Can you provide a complete test that fails?

Roger Racine




  reply	other threads:[~1999-07-12  0:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-11  0:00 discriminant fluffy_doo
1999-07-12  0:00 ` Roger Racine [this message]
1999-07-12  0:00   ` discriminant fluffy_doo
1999-07-12  0:00     ` discriminant Roger Racine
1999-07-13  0:00       ` discriminant fluffy_puff
1999-07-13  0:00         ` discriminant Roger Racine
1999-07-13  0:00         ` discriminant Ted Dennison
1999-07-13  0:00           ` discriminant fluffy_dong
1999-07-15  0:00             ` discriminant Ted Dennison
1999-07-16  0:00               ` discriminant fluffy_puff
  -- strict thread matches above, loose matches on Subject: below --
1997-01-13  0:00 discriminant AGBOH CHARLES
1997-01-13  0:00 ` discriminant KJPrice
1997-01-15  0:00 ` discriminant Michael F Brenner
replies disabled

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