Decimal fixed point representations 86-12-01 AI-00343/05 1
| !standard 03.05.09 (10) 86-12-01 AI-00343/05
| !class ramification 85-06-18
| !status approved by WG9/AJPO 86-11-26
| !status approved by Director, AJPO 86-11-26
| !status approved by WG9/Ada Board 86-11-18
!status panel/committee-approved 86-08-07 (reviewed)
!status committee-approved (8-0-1) 86-05-12 (pending editorial review)
!status work-item 86-04-08
!status received 85-06-18
!references 83-00558, 83-00565
!topic Decimal fixed point representations
!summary 86-07-01
An implementation can use decimal or binary representations for fixed point
values as long as all model numbers are represented exactly.
!question 86-04-15
Can an implementation represent a fixed point number in decimal form if small
is not specified or if small is specified as a power of 10?
!response 86-09-05
An implementation can use decimal or binary representations for fixed point
values as long as all model numbers are represented exactly, but using a
decimal representation will not necessarily save space. For example,
consider the declaration:
type FIX is delta 0.1 range -99.5 .. 99.5;
The model number mantissas consist of all integers in the range -2047 .. 2047
since (in the absence of a representation clause specifying FIX'SMALL), the
value of small must be 0.0625 (3.5.9(5)). This means the model numbers cover
the range -2047 * 0.0625 (which is -128.0 + 0.0625) through 128.0 - 0.0625.
Now consider the following declarations:
A : FIX := FIX'LAST;
B : FIX := 0.5;
G : BOOLEAN := A + B > 98.0;
The sum, A + B, is 100.0, which belongs to the range of model numbers for
FIX, so no exception can be raised when computing this sum even though the
result lies outside the subtype FIX.
If the model numbers are represented in decimal notation, four digits are
required to represent the required range of mantissa values. Even the
mantissa for the model number 99.5 requires four decimal digits (since this
mantissa value is 1592).
Now if a length clause specifying FIX'SMALL is given, the situation is
somewhat different:
Decimal fixed point representations 86-12-01 AI-00343/05 2
for FIX'SMALL use 0.1;
The model numbers in this case cover the range -(1023 * 0.1) .. 102.3, so it
is still required that 99.5 + 0.5 be evaluated without raising NUMERIC_ERROR.
This means computations using the predefined arithmetic operations must
generally use four decimal digits to ensure NUMERIC_ERROR is not raised
incorrectly. On the other hand, three decimal digits will suffice to hold
stored values of type FIX since these values can never lie outside the range
-99.5 .. 99.5.
If binary representation is used when FIX'SMALL is 0.1, the set of model
numbers is the same, of course. The value 1023 requires 10 bits and the
value 995 also requires 10 bits, so there is no difference between the size
of stored values of subtype FIX and the minimum size needed for values of the
base type.
In short, the answer to the question is, "Yes, decimal representation can be
used for the model numbers if accuracy and range requirements are satisfied."