comp.lang.ada
 help / color / mirror / Atom feed
* Fixed Point Numbers
@ 1999-05-27  0:00 Philip Bradley
  1999-05-28  0:00 ` Robert Dewar
  0 siblings, 1 reply; 5+ messages in thread
From: Philip Bradley @ 1999-05-27  0:00 UTC (permalink / raw)


What is the impact of the differing deltas in the following type
definitions :

type Long_Type is delta 180.0/2**31 range -180.0 .. 180.0;
for Long_Type'Small use 180.0/2**31;
for Long_Type'Size use 32;

and

type Long_Type is delta 256.0/2**31 range 
   -180.0 .. 180.0 - (180.0/2**31);
for Long_Type'Small use 180.0/2**31;
for Long_Type'Size use 32;


The first definition is the desired definition (and compiles using
Gnat).  Unfortunately the 2nd one is as close as I can get using a
different compiler - one I am having to use, but not by choice!

I am really only interested in the effect on the attributes, operators
etc. of Long_type if the 2nd definition is used rather than 1st.  Does
anyone know?


-- 
Philip Bradley




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

* Fixed Point Numbers
@ 1999-05-27  0:00 Robert I. Eachus
  1999-06-08  0:00 ` Robert A Duff
  0 siblings, 1 reply; 5+ messages in thread
From: Robert I. Eachus @ 1999-05-27  0:00 UTC (permalink / raw)


Philip Bradley wrote:
  
> The first definition is the desired definition (and compiles using
> Gnat).  Unfortunately the 2nd one is as close as I can get using a
> different compiler - one I am having to use, but not by choice!

    You should be pleased that both compilers will allow you to get what
you want, and my hat is off to GNAT for supporting the first definition.
 
> I am really only interested in the effect on the attributes, operators
> etc. of Long_type if the 2nd definition is used rather than 1st.  Does
> anyone know?
 
    In both cases you should get exactly the same representation, and
operations that use hardware overflow to do range checking, although you
may (or may not) get different values for 'Last.  The definition of
fixed point types cleverly does not require that the end points of the
specified range be values of the (sub)type.  This allows the compiler in
both cases to exclude the value +180.0 from the representable values for
the type and fit it exactly in 32-bits.  (By the rules you can also
exclude -180.0, but I would expect this only on ones-complement
machines.)
-- 

                                        Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




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

* Re: Fixed Point Numbers
  1999-05-27  0:00 Fixed Point Numbers Philip Bradley
@ 1999-05-28  0:00 ` Robert Dewar
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Dewar @ 1999-05-28  0:00 UTC (permalink / raw)


In article <z64AzHA$uZT3Ewor@the-shieling.demon.co.uk>,
  Philip Bradley <philip@the-shieling.demon.co.uk> wrote:
> What is the impact of the differing deltas in the following
type
> definitions :
>
> type Long_Type is delta 180.0/2**31 range -180.0 .. 180.0;
> for Long_Type'Small use 180.0/2**31;
> for Long_Type'Size use 32;

Right, GNAT will allow this, and indeed even if you did not
have the Size clause would use a size of 32. What GNAT does
is to include the end points, UNLESS this would cause the size
to get awkwardly bigger (32 to 33 bits certainly counts :-)
in which case it will exclude end points as allowed by the RM.

This behavior is explicitly allowed (and indeed one may say
intended, since this is the reason that a compiler is allowed
to exclude the end points), but unfortunately, compilers are
not required to take this reasonable approach, and you may
have to manually exclude the end point.

The representations should be identical in either case, so the
second form is the more portable, if less convenient, form.

Robert Dewar
Ada Core Technologies


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




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

* Re: Fixed Point Numbers
  1999-05-27  0:00 Robert I. Eachus
@ 1999-06-08  0:00 ` Robert A Duff
  1999-06-09  0:00   ` Robert I. Eachus
  0 siblings, 1 reply; 5+ messages in thread
From: Robert A Duff @ 1999-06-08  0:00 UTC (permalink / raw)


"Robert I. Eachus" <eachus@mitre.org> writes:

>     In both cases you should get exactly the same representation, and
> operations that use hardware overflow to do range checking, although you
> may (or may not) get different values for 'Last.  The definition of
> fixed point types cleverly does not require that the end points of the
                    ^^^^^^^^
> specified range be values of the (sub)type. ...

You misspelled "confusingly".  ;-)

After all, I don't expect this:

    type T is range -2**31..2**31;

to fit in 32 bits!

- Bob
-- 
Change robert to bob to get my real email address.  Sorry.




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

* Re: Fixed Point Numbers
  1999-06-08  0:00 ` Robert A Duff
@ 1999-06-09  0:00   ` Robert I. Eachus
  0 siblings, 0 replies; 5+ messages in thread
From: Robert I. Eachus @ 1999-06-09  0:00 UTC (permalink / raw)




Robert A Duff wrote:
  
> You misspelled "confusingly".  ;-)

   No, I meant cleverly:

  "An ordinary_fixed_point_definition defines an ordinary fixed point
type whose base range includes at least all multples of small that are
between the bounds specified in the real_range_specification. The base
range of the type does not necessarily include the specified bounds
themselves.  An ordinary_fixed_point_definition also defines a
constrained subtype of the type, with each bound of its range given by
the closer to zero of:

  "    the value of the conversion to the fixed point type of the
corresponding expression of the real_range_specification;

  "    the corresponding bound of the base range." RM 3.5.9 (13-15)

    In Ada 83 the wording was very confusing and led to more than one AI
(AI-143, AI-144, and AI-340):

  "For a fixed point constraint that includes a range constraint, the
model numbers include zero and all multiples of small whose mantissa can
be expressed using exactly B binary digits, where the value of B is
chosen as the smallest integer number for which each bound of the
specified range is either a model number or lies at most small distant
from a model number..." RM83 3.5.9(6)

> After all, I don't expect this:

>    type T is range -2**31..2**31;

> to fit in 32 bits!

   Good, because in Ada 95, it may fit, but it need not.  For example on
36-bit, 48-bit, or 64-bit machines, I would expect objects of this type
by default to fit in one word and have 2**32 + 1 possible values for the
subtype.

-- 

                                        Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




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

end of thread, other threads:[~1999-06-09  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-27  0:00 Fixed Point Numbers Philip Bradley
1999-05-28  0:00 ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1999-05-27  0:00 Robert I. Eachus
1999-06-08  0:00 ` Robert A Duff
1999-06-09  0:00   ` Robert I. Eachus

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