Microchip Technology SW006023-2 데이터 시트
Supported Data Types and Variables
2012 Microchip Technology Inc.
DS51686E-page 97
Binary floating-point values are sometimes misunderstood. It is important to remember
that not every floating-point value can be represented by a finite sized floating-point
number. The size of the exponent in the number dictates the range of values that the
number can hold, and the size of the mantissa relates to the spacing of each value that
can be represented exactly. Thus the 64-bit floating-point format allows for values with
a larger range of values and that can be more accurately represented.
that not every floating-point value can be represented by a finite sized floating-point
number. The size of the exponent in the number dictates the range of values that the
number can hold, and the size of the mantissa relates to the spacing of each value that
can be represented exactly. Thus the 64-bit floating-point format allows for values with
a larger range of values and that can be more accurately represented.
So, for example, if you are using a 32-bit wide floating-point type, it can exactly store
the value 95000.0. However, the next highest number it can represent is (approxi-
mately) 95000.00781 and it is impossible to represent any value in between these two
in such a type as it will be rounded. This implies that C/C++ code which compares float-
ing-point type may not behave as expected. For example:
the value 95000.0. However, the next highest number it can represent is (approxi-
mately) 95000.00781 and it is impossible to represent any value in between these two
in such a type as it will be rounded. This implies that C/C++ code which compares float-
ing-point type may not behave as expected. For example:
volatile float myFloat;
myFloat = 95000.006;
if(myFloat == 95000.007) // value will be rounded
LATA++; // this line will be executed!
in which the result of the if() expression will be true, even though it appears the two
values being compared are different.
values being compared are different.
The characteristics of the floating-point formats are summarized in Table 6-2. The sym-
bols in this table are preprocessor macros which are available after including
<float.h>
bols in this table are preprocessor macros which are available after including
<float.h>
in your source code. Two sets of macros are available for float and
double
types, where XXX represents FLT and DBL, respectively. So, for example,
FLT_MAX
represents the maximum floating-point value of the float type. DBL_MAX
represents the same values for the double type. As the size and format of float-
ing-point data types are not fully specified by the ANSI Standard, these macros allow
for more portable code which can check the limits of the range of values held by the
type on this implementation.
ing-point data types are not fully specified by the ANSI Standard, these macros allow
for more portable code which can check the limits of the range of values held by the
type on this implementation.
TABLE 6-2:
RANGES OF FLOATING-POINT TYPE VALUES
Symbol
Meaning
32-bit Value
64-bit Value
XXX
_RADIX
Radix of exponent representation 2
2
XXX
_ROUNDS
Rounding mode for addition
1
XXX_MIN_EXP
Min. n such that FLT_RADIX
n-1
is
a normalized float value
-125
-1021
XXX_MIN_10_E
XP
Min. n such that 10
n
is a
normalized float value
-37
-307
XXX_MAX_EXP
Max. n such that FLT_RADIX
n-1
is a normalized float value
128
1024
XXX_MAX_10_E
XP
Max. n such that 10
n
is a
normalized float value
38
308
XXX_MANT_DIG
Number of FLT_RADIX mantissa
digits
digits
24
53
XXX_EPSILON
The smallest number which
added to 1.0 does not yield 1.0
added to 1.0 does not yield 1.0
1.1920929e-07
2.22044604925
03131e-16
03131e-16