comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Ada decimal types
Date: Fri, 05 May 2006 11:49:04 -0500
Date: 2006-05-05T11:49:04-05:00	[thread overview]
Message-ID: <ZcKdnZAJrtSdH8bZRVn-jQ@comcast.com> (raw)
In-Reply-To: sKG6g.6427$TT.4592@twister.nyroc.rr.com

> A decimal type is a fixed pointed type.  I don't want to use a binary fixed
> point because it would change the precision.  Currently any value of
> microsecond granularity can be represented.  If I use a binary fixed point,
> that would change.
    I think you are expecting a fixed point decimal type to be stored in
decimal notation.  The value 1/10 could be stored precisely as "0.1",
but 1/10 could not be stored precisely as a binary fraction.

  But that's not how Ada "fixed point", even decimal fixed point, works.
"The set of values of a fixed point type comprise the integral multiples
of a number called the 'small' of the type." ARM 3.5.9(8)  The only
difference between a decimal and an ordinary fixed point is that the
'small' for a decimal is a power of ten, while the 'small' for an
ordinary is typically a power of two (unless you specify otherwise).
Thus a decimal fixed point type with a delta of 1/10 would be stored,
as integer multiples of 1/10.  The value 1/10 would be stored as 1,
with the implied scaling factor of "divide by 10".
  So
type Mission_Time_Type is delta 1.0e-6 digits 16 range 0.0 .. (2.0**32) - 1.0;
will store the number of microseconds.  In effect your current record
with two 32 bit integers is storing the same thing, it just stores
(number of microseconds)/1_000_000 in one word and
(number of microseconds) mod 1_000_000 in the other word, while type
Mission_Time_Type would store
(number of microseconds)/2**32 in its upper 32 bits and
(number of microseconds) mod 2**32 in its upper 32 bits.
Since all arithmetic is done conceptually as integers (the only difference
is in how they are stored), they should give the same answers and the
same precision.



  reply	other threads:[~2006-05-05 16:49 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-04 15:23 Ada decimal types REH
2006-05-04 18:17 ` Jeffrey R. Carter
2006-05-04 22:20   ` REH
2006-05-05  9:14 ` Stephen Leake
2006-05-05 11:33   ` REH
2006-05-05 16:49     ` tmoran [this message]
2006-05-05 18:08       ` REH
2006-05-05 18:49         ` tmoran
2006-05-05 18:59           ` REH
2006-05-06  8:59         ` Keith Thompson
2006-05-06 14:01           ` REH
2006-05-06 15:48             ` Simon Wright
2006-05-06 16:39               ` REH
2006-05-08 21:19                 ` Randy Brukardt
2006-05-09 23:21                   ` REH
2006-05-10  1:08                     ` Keith Thompson
2006-05-10  5:37                     ` Simon Wright
2006-05-10 12:22                       ` REH
2006-05-10 20:47                         ` Randy Brukardt
2006-05-10 21:26                           ` REH
2006-05-10 20:52                       ` Randy Brukardt
2006-05-11  5:51                         ` Simon Wright
2006-05-11 22:33                           ` Randy Brukardt
2006-05-05 20:32     ` 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