comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Fixed point attributes
Date: Wed, 16 Mar 2005 16:36:35 -0600
Date: 2005-03-16T16:36:35-06:00	[thread overview]
Message-ID: <P8mdnccUBYz3KaXfRVn-vQ@megapath.net> (raw)
In-Reply-To: 1110998197.165590.63800@z14g2000cwz.googlegroups.com

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









  reply	other threads:[~2005-03-16 22:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-16 18:36 Fixed point attributes brian.b.mcguinness
2005-03-16 22:36 ` Randy Brukardt [this message]
2005-03-17 13:31   ` brian.b.mcguinness
2005-03-17 23:30     ` Randy Brukardt
replies disabled

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