Zilog EZ80F916 User Manual
Page 165

UM014423-0607
Using the ANSI C-Compiler
ZiLOG Developer Studio II
eZ80Acclaim!
®
User Manual
145
If the sign bit is negative (in the case of a signed type), take the two’s complement of the
value before decoding the fractional number. For example, to decode the value
0xb000
into a real number representation, first negate the value to obtain
0x5000
. Then, sum the
powers of two for each bit set as follows:
Therefore,
signed 0xb000
represents –(2
-1
+ 2
-3
) = –0.625.
The minimum resolution of the
fract
value varies, depending on the size and signedness
of the data type, as follows:
char fract
: 1/2
7
= 0.0078125
unsigned char fract
: 1/2
8
= 0.0039063
short fract
: 1/2
15
= 0.000030518
unsigned short fract
: 1/2
16
= 0.000015259
int fract
: 1/2
23
= 0.00000011921
unsigned int fract
: 1/2
24
= 0.000000059605
Assigning Values to fract Variables
When assigning values of
fract
variables, floating-point constant syntax can be used.
For example:
short fract f = -0.5;
f= -5/0.9;
Assignments between
fract
s of different sizes only move the least significant bytes, and
hence the resulting value is distorted. Assignments between
signed
and
unsigned
ver-
sions of a
fract
do not preserve the signedness of the value, and hence the resulting value
is distorted. Assignment between
fract
and
float
(and vice versa) is allowed—only the
fractional part is transacted between the objects, and the integral part (if any) is ignored.
Fractional Expressions
In the fractional fixed-point system, fractional values are considered a higher order type
than floating-point values. If
float
s or
double
s are in an expression containing
fract
s,
the
float
s and
double
s are converted to
fract
s as necessary, even though a loss of
accuracy might occur. The fractional fixed-point model assumes that the operation’s effi-
ciency is more important than its accuracy.
s
2
-1
2
-2
2
-3
2
-4
2
-5
2
-6
2
-7
2
-8
2
-9
2
-10
2
-11
2
-12
2
-13
2
-14
2
-15
0
.1
0
1
0
0
0
0
0
0
0
0
0
0
0
0