comp.lang.ada
 help / color / mirror / Atom feed
From: csampson@inetworld.net (Charles H. Sampson)
Subject: Re: 32-bit float and 64-bit float
Date: Tue, 15 Aug 2017 11:11:56 -0700
Date: 2017-08-15T11:11:56-07:00	[thread overview]
Message-ID: <1naspc7.17e30f01qpxt22N%csampson@inetworld.net> (raw)
In-Reply-To: omrnp7$1ko3$1@gioia.aioe.org

Victor Porton <porton@narod.ru> wrote:

> Dmitry A. Kazakov wrote:
> 
> > On 14/08/2017 00:29, Victor Porton wrote:
> >> What is the best way to define in Ada types which are expected to
> >> contain:
> >> 
> >> 1. 64-bit floating point numbers (incl. ±Inf, ±0, NaN);
> >> 
> >> 2. 32-bit floating point numbers (incl. ±Inf, ±0, NaN).
> > 
> > There is no way since you specified neither the precision and range nor
> > the floating-point representation format IEEE 754, IBM, DEC etc.
> > 
> > Ada's way is the former. The latter is not possible in general.
> > 
> > If you have a requirement to support a specific representation, e.g. for
> > I/O you have to convert it forth and back to an Ada type most close to
> > it. In Simple Components there are packages to convert IEEE 754 floats:
> > 
> > http://www.dmitry-kazakov.de/ada/components.htm#IEEE_754
> 
> I understand this.
> 
> My question was how to do it in the "best" (not "perfect") way.
> 
> I think Float and Long_Float will do the job on most compilers and machines.
> But maybe I should instead use "digits" in Ada? If yes, then how many
> digits?

Yes, this is the "right" way. The Ada way is to specify the (numerical)
attributes to do your job and let the compiler worry about choosing the
representation that accomplishes this. In the case of floating-point
(real) the specification is in terms of number of specific digits and
range.

If you're working on a machine that supports IEEE 754 you'll get the odd
values. The infinities can be a significant pain in the posterior if
there's any chance you'll be near extreme values. For this reason, you
should always do a mathematical analysis of your application and use the
Range specification. A good compiler will then keep you away from the
infinities.

Nans can pop up at really inconvenient times. If there's a possibility
that they might, heroic action is required. The compiler should take
care of +0 and -0 issues.

Charlie
-- 
Nobody in this country got rich on his own.  You built a factory--good.
But you moved your goods on roads we all paid for.  You hired workers we
all paid to educate. So keep a big hunk of the money from your factory.
But take a hunk and pay it forward.  Elizabeth Warren (paraphrased)


      parent reply	other threads:[~2017-08-15 18:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-13 22:29 32-bit float and 64-bit float Victor Porton
2017-08-14  6:55 ` Dmitry A. Kazakov
2017-08-14  8:42   ` Victor Porton
2017-08-14  9:01     ` Dmitry A. Kazakov
2017-08-15 18:11     ` Charles H. Sampson [this message]
replies disabled

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