comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <Stephen.Leake@gsfc.nasa.gov>
Subject: Re: Help ... CONSTRAINT_ERROR
Date: 1999/12/02
Date: 1999-12-02T00:00:00+00:00	[thread overview]
Message-ID: <un1rtjjxi.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: 81vfu6$sem$1@tobruk.sydney.gecm.com

"jxredi" <jxredi@gecms.com.au> writes:

> 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
> ??

I cleaned this up as:

with Text_IO;
procedure Jxredi is
   package R_IO is new Text_IO.Float_IO (Float);
   NUM : STRING :=   "hi there";
   FNUM : Float := 0.75;
begin
   R_IO.Put (NUM, FNUM);
end Jxredi;

compiling and running with GNAT gives:

./jxredi.exe  > jxredi.out

raised ADA.IO_EXCEPTIONS.LAYOUT_ERROR : a-tiflau.adb:218

Since GNAT comes with source code, I looked at 'a-tiflau.adb:218'
(cool!). The problem is that the string NUM is too short for the
canonical representation of FNUM.

Note that the call to R_IO.Put writes the image of FNUM into the
string NUM; is that what you wanted it to do? If you are used to C
printf, you probably wanted the following output:

hello there 0.75

Here's a program that does that:

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
procedure Jxredi is
   NUM : String := "hello there";
   FNUM : Float := 0.75;
begin
   Put (NUM);
   Put (FNUM, Fore => 2, Aft => 2, Exp => 0);
end Jxredi;

./jxredi.exe 
hello there 0.75


-- Stephe




  parent reply	other threads:[~1999-12-02  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
1999-11-30  0:00   ` Preben Randhol
1999-11-30  0:00     ` reason67
1999-11-30  0:00     ` Robert A Duff
1999-11-30  0:00       ` Ted Dennison
1999-11-30  0:00     ` David C. Hoos, Sr.
1999-11-30  0:00 ` Preben Randhol
1999-12-02  0:00 ` Stephen Leake [this message]
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