From: Richard D Riehle <laoXhai@ix.netcom.com>
Subject: Re: strings to floats/integers
Date: 1998/08/26
Date: 1998-08-26T12:53:26-07:00 [thread overview]
Message-ID: <6s1p3m$4sp@sjx-ixn1.ix.netcom.com> (raw)
In-Reply-To: 6s1g0t$lk6@hacgate2.hac.com
In article <6s1g0t$lk6@hacgate2.hac.com>,
"David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> wrote:
In response to the following message,
>
>Richard D Riehle wrote in message <6s1e9k$bgq@sjx-ixn5.ix.netcom.com>...
>>In article <35e41033.9324314@200.223.0.87>,
>
>>The conversion between strings and float and strings and integers can
>>easily be accomplished using Ada.Text_IO. Note that for
>>
>> Ada.Text_IO.Integer_IO
>> and Ada.Text_IO.Float_IO
>>
>>there are Get and Put operations defined for conversion between strings
>>and the desired numeric type.
>True enough, Richard, but I would only use an instance of a numeric io
>generic for the case where I wanted to control the output format. If I
will
>accept exponential notation for floating output, I would use the 'image
>attribute. For all conversion from strings, I would use the 'value
>attribute.
>David C. Hoos, Sr.
Formatting can often be an important issue. The attribute method,
while a useful brute-force method of achieving the conversions,
will not always provide the more discipline result of Get and Put.
Also, the use of 'Value for an invalid string will raise a constraint
error. Would you rather see Ada.Text_IO.Data_Error. There are many
other reasons for using the Get and Put, but I know you are aware of
them. One anecdote might be useful. In converting floating point
numbers from a VAX (the sign is in bit 15) to floating point for an
IBM mainframe (the sign is bit 31) the Get and Put from Float_IO
served well as a way to properly format the data from one machine to
another. The ability to differentiate between data errors and
constraint errors was important in this situation.
Richard Riehle
richard@adaworks.com
http://www.adaworks.com
next prev parent reply other threads:[~1998-08-26 0:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-08-26 0:00 strings to floats/integers Mr Pinga
1998-08-26 0:00 ` Richard D Riehle
1998-08-26 0:00 ` David C. Hoos, Sr.
1998-08-26 0:00 ` Richard D Riehle [this message]
1998-08-29 0:00 ` Matthew Heaney
1998-09-03 0:00 ` Bob Fletcher
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox