* Tenacious:
Why is it that when I multiply two double values like this:
double Multi = 100.0;
double Force = 0.29;
double Result = Multi * Force;
I get Result = 28.999999999996 instead of 29.0? I'm not an expert
mathematician, but 0.29 * 100 has always been 29 as far as I can
remember. If anyone can help me understand this, I would appreciate it
very much.
A 'double' value is represented using some number of bits, typically 64.
There are 2^64 different patterns of bit-values of length 64, and
hence, for a 64-bit 'double', at most 2^64 possible different 'double'
values can exist. Typically these possible values are spread over a
fairly large range, say about 5*10^-324 up to 1.7*10^308, plus an exact
0; the distance between two adjacent 'double' values is very small for
very small numbers, and very large for very large numbers.
Which means that /most/ exact number values you can think of simply
cannot be represented exactly as 'double' values: such a value is
instead represented by the closest 'double' value.
Due to the way 'double' values are typically represented, typically
small integers /can/ be represented exactly. So you can assume that
your number 100.0 is represented exactly since it's a small integer,
while 0.29 is represented by some closest possible 'double' value which
is just slightly less than or more than 0.29. In fact, it seems that
you have established that that value, for your C++ implementation,
corresponds to roughly 0.28999999999996.