beautypg.com

Char and short enumerations – Zilog EZ80F916 User Manual

Page 166

background image

UM014423-0607

Using the ANSI C-Compiler

ZiLOG Developer Studio II

eZ80Acclaim!

®

User Manual

146

Basic Fractional Arithmetic
The compiler supports signed/unsigned fractional arithmetic for the +, -, and * operators.
The binary operators +, -, and * on the

fract

data type give correct results only if both

the operands are of same size and of same sign-type. Otherwise, the values are distorted
for the reasons cited in “Assigning Values to fract Variables” on page 145.

All other arithmetic operators on

fract

treat the data as if they were of integral types

(ignoring the

fract

keyword), and hence the resulting value might not make sense within

the context of

fract

.

Bitwise Logical and Shift Operators
The compiler supports all bitwise logical operators, including &, |, ^, <<, and >> for frac-
tional types, although ANSI does not allow these operations for floating-point types. You
can use these operators to vary the position of the binary point in a fractional number. This
feature can be very useful when the result of a fractional expression is not within the range
of –1 to +1 or 0 to +1 but a wider range such as –3 to +3.

Scaled Fractional Arithmetic
You can alter the range of a fractional fixed-point value by modifying where its implied
binary point resides. You can perform this operation using the shift operators as follows:

unsigned short fract f1,f2;

int int_part;

unsigned short fract fract_part;

f2 = .55;

f2 >>= 3;

/* move the binary point to right */

f1 = f2 + f2;

/* .55 + .55 = 1.1 */

int_part = (f1 & 0xe000) >> 13;

/* 1 */

fract_part = f1 << 3;

/* 0.1 */

Although

fract

arithmetic assumes that the binary point is just after the most significant

bit (or after the sign bit in the case of a signed type), you can perform the same operations
on

fract

s that have been shifted to move the binary point.

NOTE: However, be careful when dealing with negative

signed

fract

s and make sure that all

values involved in an operation have their binary points aligned.

Char and Short Enumerations

The enumeration data type is defined as

int

as per ANSI C. The C-Compiler provides

language extensions to specify the enumeration data type to be other than

int

to save

space. The following syntax is provided by the C-Compiler to declare them as

char

or

short

:

enum
{
RED = 0,
YELLOW,

This manual is related to the following products: