Description of why floating point numbers may lose precision in Visual C++ (145889)
The information in this article applies to:
- Microsoft Visual C++ 1.0
- Microsoft Visual C++ 1.5
- Microsoft Visual C++ 1.51
- Microsoft Visual C++ 1.52
- Microsoft Visual C++ 2.0
- Microsoft Visual C++ 2.1
- Microsoft Visual C++ 2.2
- Microsoft Visual C++ 4.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q145889
The information in this article is included in the documentation starting
with Visual C++ 5.0. Look there for future revisions.
SUMMARY
Floating point decimal values generally do not have an exact binary
representation. This is a side effect of how the CPU represents floating
point data. For this reason, you may experience some loss of precision, and
some floating point operations may produce unexpected results.
This behavior is the end result of one of the following:
- The binary representation of the decimal number may not be exact.
-or-
- There is a type mismatch between the numbers used (for example, mixing
float and double).
To resolve the behavior, you can either ensure that the value is greater or
less than what you need, or you can get and use a Binary Coded Decimal
(BCD) library that will maintain the precision.
REFERENCES
For information on other predefined constants, please see:
Microsoft Developer Network: C Floating-Point Constants Microsoft
Modification Type: | Major | Last Reviewed: | 6/10/2005 |
---|
Keywords: | kbhowto kbArtTypeINF kbcode kbCompiler kbinfo KB145889 kbAudDeveloper |
---|
|