Actually, it's 0.1xxxxx in binary, usually. IOW, the mantissa
value is always in the range [0.5, 1).
Not 1000.xxx or 0.xxx, anyways--
if something like,
float x=1000;
float y=1000.43;
std::cout<< y-x<< std::endl;
will result in 0.429xxxx or whatever,
It can't, in general. Try something like 1.0/3.0.
Because it probably uses more digits of precision than
'float'...
Or because it uses decimal arithmetic. Which is not only
slower (usually), but has the disadvantage of variable
precision.
If you're doing bookkeeping, or working in some other context
where the rounding rules are determined by a legal specification
based on decimal arithmetic, then you need a decimal class which
does decimal arithmetic. Typically, however, such applications
aren't "numbers crunchers", so you can afford the extra runtime.
Yes, look on the web for "arbitrary precision floating point
library".
I'd be interested in seeing one capable of storing the exact
value of pi, or even the exact value of sqrt(2.0). Some numbers
require infinite precision in any base.
In practice, even simple division is a problem. You can only
store 1/n precisely in a finite number of bits if the base being
used is n or a multiple of n. In order to guarantee exactness,
you'd have to use some sort of rational representation.
Note that 10 is a multiple of 2, so with enough bits, you can
store any decimal representation. But this just begs the
question: numbers don't always come from literals or input
strings; they are also the result of expressions like a/b or
sqrt(c).
Or you could use rationals (if your algorithm allows that).
Or go for some kind of mathematical formula for the number.
You're still going to be SOL with numbers like Pi or e (which
aren't from a formula, really).
They can be expressed as the results of an equation.
The built-in FP types are limited, there are only three. In
addition to the two you've named there is the 'long double',
which is allowed to be implemented as 'double'. Sucks, don'
it?
Although neither made it into the final draft, there were
proposals on the table for decimal arithmetic and a rational
class. For that matter, I think the decimal arithmetic is being
adopted in the form of a technical report or something like
that.