Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is the type of thing that makes mathematicians flying tackle computer scientists.

the CS: "Hey, it's round off error. Get used to it"

the Mathematician: "Fix IT!!"



It's not "round off error", though. More like:

"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."


Well, it's more like:

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.


The mathematician: That's fine for 22/7. Now, go fix your computer so it knows how to count to 0.3, kthxbye


As a mathematician I do not value 0.3 above 22/7.


0.3 is a rational too, it's just 3/10.

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.


I saw the occasional number in my studies.

We'd rather calculate with knows than numbers. (See http://en.wikipedia.org/wiki/Knot_theory)


No doubt, for years I've called quantization errors round off errors. But there's no rounding, it's an approximation error.


> This is the type of thing that makes mathematicians flying tackle computer scientists.

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.


And then you discover that you have a square root in your computation.


Even then it doesn't matter fully. There are some languages with supported data types where you can actually write the equivalent of.

  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.


Which ones? It honestly seems unlikely to me that this would work well in practice.


Good point, but rational numbers aren't closed under power/square root operation :)


Well, which data type would you like to store the value of PI in? I mean, you could re-calculate it to arbitrary precision every time you use it... just don't try to store it at "full" precision using floats or decimals.


If it where me I'd store the value of PI as a structure containing an IEEE double, a decimal representation of, say, 100 digits and a pointer to a function to that can evaluate PI to an arbitrary precision.

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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: