This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Fwd: Formatted Read Accuracy]


Hi Blime,

Floating point numbers -- IEEE 754, 32-bit "float", 64-bit "double", or any of the other more-or-less standard formats -- cannot perfectly represent any arbitrary decimal portion of all rational numbers.

For instance, 0.5 can be perfectly represented.

Consider that "0.5" (decimal) is "0.8" (hexadecimal). Exactly.

0.1 cannot be perfectly represented.

Consider that "0.1" (decimal) would be "0.1999999999999999999999999999999..." (hexadecimal). Since floating point numbers do not have infinite precision, some rounding occurs.

To alleviate the problem, consider using fixed point numbers, or using BCD numbers.

Sincerely,
--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]