comp.lang.ada
 help / color / mirror / Atom feed
From: reason67@my-deja.com
Subject: Re: Help ... CONSTRAINT_ERROR
Date: 1999/11/30
Date: 1999-11-30T00:00:00+00:00	[thread overview]
Message-ID: <820qf9$ic3$1@nnrp1.deja.com> (raw)
In-Reply-To: 81vfu6$sem$1@tobruk.sydney.gecm.com

In article <81vfu6$sem$1@tobruk.sydney.gecm.com>,
  "jxredi" <jxredi@gecms.com.au> wrote:
>
> Hi,
> I was wondering if you could help me out with this problem (using
ADA83) :
>
> package R_IO is new TEXT_IO.FLOAT_IO(Float);
> NUM : STRING :=   "hi there";
> FNUM : Float := 0.75;
> R_IO.PUT(NUM,FNUM);   -- this is where the problem is ... but what's
wrong
> ??
>
> ------------
> RUN-TIME ERROR :     "constraint_error".

The code you posted would not compile:
      NUM : STRING := "hi there";
      The string length of a variable has to be defined. If this was a
constant, it would work as it would get the length from the string, but
as a variable, you would have to say (1 .. 8) after the String. Assuming
a typo and it is (1 .. 8), I know the problem:

R_IO.PUT (NUM, FNUM);

Is this call:

procedure Put(To   : out String;
              Item : in Num;
              Aft  : in Field := Default_Aft;
              Exp  : in Field := Default_Exp);


Num is 8 characters long and if you are using float, most likely that is
a single precisions IEEE floating point (have to know your compiler to
be certain as it is implementation defined) and without specifying the
aft or exponent it will try to write a 6 digit string with 1 decimal and
3 characters for exponent and 1 character for sign in the form
"sd.dddddEnn" which is longer than 8 characters. That is causing your
constaint error. Change Num to String (1 .. 20) and it should work. Once
it does see how many digits are displayed (probably 6) and how long the
exponent is and add 4 characters and that is the minimum size string you
should use.

Hope this helps.
---
Jeffrey Blatt


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




  reply	other threads:[~1999-11-30  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-30  0:00 Help ... CONSTRAINT_ERROR jxredi
1999-11-30  0:00 ` reason67 [this message]
1999-11-30  0:00   ` Preben Randhol
1999-11-30  0:00     ` David C. Hoos, Sr.
1999-11-30  0:00     ` Robert A Duff
1999-11-30  0:00       ` Ted Dennison
1999-11-30  0:00     ` reason67
1999-11-30  0:00 ` Preben Randhol
1999-12-02  0:00 ` Stephen Leake
1999-12-06  0:00 ` skamn
replies disabled

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