6.7 Floating point variables
-----------------------------
6.7.1 Format of floating point variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Floating-point values in C-- are represented as type 'float'. This
type corresponds to a single-precision floating point number (in Pascal
or Fortran).
The format for representing floating-point data includes three
fields: sign, magnitude, and order. The sign is defined by the the first
significant bit. The magnitude field contains the significant bits of the
number, and the exponent field contains degree 2 and defines the scaling
multiplier for the magnitude.
31 30.....23 22........0
| | | | |
| | | -------------- - magnitude field
| ------------------------ - exponent field
-------------------------- - sign bit
6.7.2 Floating point constants
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The compiler distinguishes a floating point number from an integer
by the presence of a decimal point. A floating point number must start
with a number from 0 to 9 or a minus sign. It may also contain an
exponent factor (power of ten), which is separated from the number by 'e'
or 'E'.
0.98
-15.75
3.14e2
1.234567E-20
6.7.3 Range of permissible values
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Real numbers of float type can range from 3.37E38 to -3.37E38. The
values closest to zero are 1.17E-38 and -1.17E-38. There is no point in
writing a floating point number with unary precision greater than 8. The
scaling factor can be +38 to -38.
6.7.4 Mathematical operations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The compiler support four primary operations on variables of type
float: addition, subtraction, multiplication and division. It also
supports increment (var++ increase by 1), decrement (var-- - decrease by
1), sign change (-var), and exchange of values (var1<>vars). The other
mathematical operations are to be performed later, or were already
performed in external libraries. Values of float variables can be
calculated using variables of other types which are automatically
converted to float type.
NOTE: The component mathematical operations are executed in the order in
which they were written, regardless of the usual mathematical rules.
6.7.5 Transformations of types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For mathematical operations which produce variables of type float,
all other types of operands are converted to float type before
calculating. When assigning another type of value to a float type
variable, it is also transformed to float type.
If during integer calculations one of the operands is a variable of
type float, the integral part of it will be separated out and will take
part in the calculations. When assigning a float-type value to an integer
variable, the integer part of it is also separated out and assigned an
integer variable.
6.7.6 Comparison operators
~~~~~~~~~~~~~~~~~~~~~~~~~~~
If during a comparison operation the left operand is a variable or an
expression of type float and the right operand is an integer, the integer
will be converted to the type float. If the left operand is an integer or
variable and the right operand is of type float, the integer part of the
right operand will be separated out and will take part in the comparison.
6.7.7 Comparing variables of type float with a 32-bit register
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed, unsigned and real data can be stored in registers. By default
unsigned numbers are considered to be stored in registers. When comparing
values of type float with 32-bit register, the type of data stored in the
register can be indicated using the modifiers 'signed', 'unsigned', or
'float'. For example:
float f=1.0;
void PROC()
{
IF( f < signed ECX) // signed number stored in register ECX
IF( unsigned EBX > f) // unsigned number stored in register EBX
IF( f == float EAX ) // float-type number stored in register EAX
}
NOTE: For comparison operations involving variables of float type, the
contents of register AX will be destroyed.