comp.lang.ada
 help / color / mirror / Atom feed
* 32-bit float and 64-bit float
@ 2017-08-13 22:29 Victor Porton
  2017-08-14  6:55 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 5+ messages in thread
From: Victor Porton @ 2017-08-13 22:29 UTC (permalink / raw)


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).

-- 
Victor Porton - http://portonvictor.org

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: 32-bit float and 64-bit float
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry A. Kazakov @ 2017-08-14  6:55 UTC (permalink / raw)


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

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: 32-bit float and 64-bit float
  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
  0 siblings, 2 replies; 5+ messages in thread
From: Victor Porton @ 2017-08-14  8:42 UTC (permalink / raw)


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?

-- 
Victor Porton - http://portonvictor.org


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: 32-bit float and 64-bit float
  2017-08-14  8:42   ` Victor Porton
@ 2017-08-14  9:01     ` Dmitry A. Kazakov
  2017-08-15 18:11     ` Charles H. Sampson
  1 sibling, 0 replies; 5+ messages in thread
From: Dmitry A. Kazakov @ 2017-08-14  9:01 UTC (permalink / raw)


On 14/08/2017 10:42, Victor Porton wrote:

> I think Float and Long_Float will do the job on most compilers and machines.

Possibly.

> But maybe I should instead use "digits" in Ada? If yes, then how many
> digits?

Yes, digits is the safe way. You find IEEE 754 precision data for 
instance in Wikipedia:

    https://en.wikipedia.org/wiki/IEEE_754

But you would, AFAIK, lose non-numeric values (like Inf), which is a 
good thing.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: 32-bit float and 64-bit float
  2017-08-14  8:42   ` Victor Porton
  2017-08-14  9:01     ` Dmitry A. Kazakov
@ 2017-08-15 18:11     ` Charles H. Sampson
  1 sibling, 0 replies; 5+ messages in thread
From: Charles H. Sampson @ 2017-08-15 18:11 UTC (permalink / raw)


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)


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-08-15 18:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox