the CS: "Hey, it's round off error. Get used to it"
the Mathematician: "Fix IT!!"
the CS: "Hey, it's round off error. Get used to it"
the Mathematician: "Fix IT!!"
"It's a base 2 fractional number with no exact decimal expansion with a finite number of digits. Display it in base 2 fractional form if you don't want to see an approximation."
Binary numbers are a countably infinite set. Decimal numbers are a countably infinite set. You can therefore map binary representation to decimal representation 1-1 with a simple mapping function.
OTOH, floating point numbers are an uncountably infinite set. The only way to map binary numbers to floating point numbers is to map to a strict subset.
The subset happens to be different when mapping binary to floating point and decimal to floating point when using IEEE754.
Anyway, mathematicians don't use numbers at all - debasing the equations by performing caculations with them is so.. gauche. Leave that to the physicists, chemists and engineers.
We'd rather calculate with knows than numbers. (See http://en.wikipedia.org/wiki/Knot_theory)
Well, it's fixable. You lose your deal of performance in order to get some absolutely valid rational numbers representation.
It's only that most tasks don't require this kind of precision.
x = 2
y = 2
1.upto 100 do
x = x ** (1 / 2)
end
1.upto 100 do
x = x ** 2
end
x == y # => true
because it handles the math by only evaluating the operations at the very end.Then I'd just just use PI as a symbol and do symbolic algebra for as long as possible. Don't evaluate it to anything until the user actually asks for a numeric representation. Once a numeric representation is required I'd pick a value from the above structure based on what has been asked for.