comp.lang.ada
 help / color / mirror / Atom feed
* Fixed point attributes
@ 2005-03-16 18:36 brian.b.mcguinness
  2005-03-16 22:36 ` Randy Brukardt
  0 siblings, 1 reply; 4+ messages in thread
From: brian.b.mcguinness @ 2005-03-16 18:36 UTC (permalink / raw)


I do not understand why Ada fixed point types have the Round attribute
but not Floor or Truncation.  Adding the later two would make fixed
point types more useful, and reduce the need for type conversions.

--- Brian




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

* Re: Fixed point attributes
  2005-03-16 18:36 Fixed point attributes brian.b.mcguinness
@ 2005-03-16 22:36 ` Randy Brukardt
  2005-03-17 13:31   ` brian.b.mcguinness
  0 siblings, 1 reply; 4+ messages in thread
From: Randy Brukardt @ 2005-03-16 22:36 UTC (permalink / raw)


<brian.b.mcguinness@lmco.com> wrote in message
news:1110998197.165590.63800@z14g2000cwz.googlegroups.com...
> I do not understand why Ada fixed point types have the Round attribute
> but not Floor or Truncation.  Adding the later two would make fixed
> point types more useful, and reduce the need for type conversions.

Ada fixed point types don't have "Round"; that's only available for decimal
types (intended primarily to be used for money). I don't know what the
thinking was for omitting Truncation for decimal types; perhaps Bob knows.

In general, you can't have attributes like that for fixed point types,
because there is no requirement that the a fixed point type can represent
integers. For instance, if you have:
    type Weird_Fixed delta 0.77 range 0 .. 100.0;
    for Weird_Fixed'Small use 0.77;

the only integers that can be represented exactly are 0 and 77. So what
would Round or Truncation mean for that sort of type? What is the result of
Weird_Fixed'Truncation (20.5)? The closest value smaller than 20 is 19.25.
That doesn't seem to be a sensible result to me.

This of course is a case where Ada's generality gets in the way. It would be
nice to have such attributes, but it would mean outlawing arbitrary small
values. I don't think smalls like this are used much, but it would be
incompatible, and there would be no real workaround if such smalls were
outlawed. (You'd have to switch to floating point, or write your own
pseudo-fixed package.) I think that would be too much of an incompatibility.

(Note that only allowing the attributes on some fixed point types would be a
generic contract model violation, so that isn't a viable solution, either.)

                       Randy.









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

* Re: Fixed point attributes
  2005-03-16 22:36 ` Randy Brukardt
@ 2005-03-17 13:31   ` brian.b.mcguinness
  2005-03-17 23:30     ` Randy Brukardt
  0 siblings, 1 reply; 4+ messages in thread
From: brian.b.mcguinness @ 2005-03-17 13:31 UTC (permalink / raw)


I see your point, but according to
http://www.grammatech.com/rm95html-1.0/rm9x-03-05-10.html,

---
  The following attributes are defined for every fixed point subtype S:

  ...
  S'Round
  S'Round denotes a function with the following specification:
  (13)
           function S'Round(X : universal_real)
             return S'Base

  (14)
  The function returns the value obtained by rounding X (away from 0,
if X is midway between two values of the type of S).
---
So I was thinking that if they could define Round they could define the
other two as well.

--- Brian




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

* Re: Fixed point attributes
  2005-03-17 13:31   ` brian.b.mcguinness
@ 2005-03-17 23:30     ` Randy Brukardt
  0 siblings, 0 replies; 4+ messages in thread
From: Randy Brukardt @ 2005-03-17 23:30 UTC (permalink / raw)


<brian.b.mcguinness@lmco.com> wrote in message
news:1111066266.099494.162830@f14g2000cwb.googlegroups.com...
> I see your point, but according to
> http://www.grammatech.com/rm95html-1.0/rm9x-03-05-10.html,
>
> ---
>   The following attributes are defined for every fixed point subtype S:

Nope; it's only defined for decimal types. You missed 3.5.10(6):

The following additional attributes are defined for every decimal fixed
point subtype S:

And Round follows that.

BTW, a better looking version of the RM (which also includes the Corrigendum
updates) can be found at:

    http://www.adaic.com/standards/ada95.html

You can also find the working draft of Ada 2005 there (with some searching).

                   Randy.




> So I was thinking that if they could define Round they could define the
> other two as well.

Makes sense, but you misread the Standard.







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

end of thread, other threads:[~2005-03-17 23:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-16 18:36 Fixed point attributes brian.b.mcguinness
2005-03-16 22:36 ` Randy Brukardt
2005-03-17 13:31   ` brian.b.mcguinness
2005-03-17 23:30     ` Randy Brukardt

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