Echelon Neuron C User Manual

Page 79

Advertising
background image

Neuron C Reference Guide

59

float_type X, A, B, C;
fl_mul(&B, &C, &X);
fl_add(&X, &A, &X);

The floating-point format can represent numbers in the range of approximately -
1*10

1038

to +1*10

1038

, with a relative resolution of approximately ±1*10

-7

.

A float_type structure data type is defined by means of a typedef in the <float.h>

file. It defines a structure that represents a floating-point number in IEEE 754
single precision format. This has one sign bit, eight exponent bits and 23

mantissa bits, and is stored in big-endian order. Processors that store data in
little-endian order represent IEEE 754 numbers in the reverse byte order. The

float_type type is identical to the type used to represent floating-point network

variables. The type declaration is shown here for reference.

typedef struct {
unsigned int sign

: 1;

// 0 = positive, 1 = negative

unsigned int MS_exponent : 7;
unsigned int LS_exponent : 1;
unsigned int MS_mantissa : 7;
unsigned long LS_mantissa;
} float_type;

See the IEEE 754 standard documentation for more details.
All the constants and functions in the <float.h> file are defined using the
Neuron C float_type floating-point format, which is a structure. Neuron C does

not permit structures to be passed as parameters or returned as values from

functions. When these objects are passed as parameters to C functions, they are
passed as addresses (using the '&' operator) rather than as values. However,

Neuron C does support structure assignment, so floating-point objects can be
assigned to each other with the '=' assignment operator.
An fl_error global variable stores the last error detected by the floating-point

functions. If error detection is desired for a calculation, application programs
should set the fl_error variable to FL_OK before beginning a series of floating-

point operations, and check the value of the variable at the end.
The errors detected are as follows:

FL_UNDERFLOW

A non-zero number could not be represented

because it was too small for the floating-point

representation. Zero was returned instead.

FL_INVALID_ARG

A floating-point number could not be converted

to integer because it was out of range; or, an

attempt was made to evaluate the square root
of a negative number.

FL_OVERFLOW

A number could not be represented because it
was too large for the floating-point

representation.

FL_DIVIDE_BY_ZERO

An attempt was made to divide by zero. This
does not cause the Neuron firmware

DIVIDE_BY_ZERO error to be logged.

Advertising