
Coding Horror: Why Do Computers Suck at Math? - Anon84
http://www.codinghorror.com/blog/archives/001266.html
======
michael_dorfman
As one who has been vocally critical of Atwood in the past for his lack of CS
knowledge, I'll take this opportunity to congratulate him for discovering
floating point arithmetic, and recognizing that math is important.

~~~
gaius
Hey, that's a bit harsh. He's a blogger, not a programmer.

~~~
vicaya
He's the main developer of stackoverflow, which I think is pretty good
compared with many other sites :)

------
csomar
The new Windows calculator calculates 999 999 999 999 999 - 999 999 999 999
998 correctly.

It's not computer problem, it's programming problem, I remember I read an
article where SteveBallmer said they have invested a lot in the XP calculator
(the last one calculate incorrectly) at that point I didn't understand why
they "invested a lot" and remade in from "Scratch".

but now it seems to be fair, calculation needs a lot of programming to get
accurate results..

~~~
wlievens
The new calculator uses arbitrary-precision arithmetic, I think.

------
lena
This is a blog that is aimed at programmers, right? Good programmers, that
even like their profession enough to read blogs about it. But the entry reads
like it is written for some "introduction to computers" blog instead. Surely
this is not new or shocking information to any programmer in 2009?

------
jules
> Computers are awesome, yes, but they aren't infinite.. yet. So any prospects
> of storing any infinitely repeating number on them are dim at best. The best
> we can do is work with approximations at varying levels of precision that
> are "good enough", where "good enough" depends on what you're doing, and how
> you're doing it. And it's complicated to get right.

Rationals?

------
RiderOfGiraffes
This isn't math, this is arithmetic. Computers are actually pretty good as
math assistants - I refer to packages such as Maple, Reduce and similar - but
what he's talking about is arithmetic. And programming arithmetic can be hard
too.

It's like someone you know saying they program, and then you discover they
write HTML, and know nothing about PHP, Perl, Python, JavaScript, <insert your
favorite language here>. Programmers snort derisively about such sweeping
ignorance, and then do the same thing in other fields by calling sums like
399999999999 - 399999999998 "math".

It isn't. Not to those who do, or have done, real math, any more than HTML
hacking is "programming", and all "hacking" is breaking into banks and
defacing web sites.

If you really care about getting your arithmetic right it's possible, but it's
hard. Here's a challenge: write a program that takes three floating point
numbers and returns their sum. I'll bet you can't get it right.

------
khandekars
Computers are useful in maths, and like all tools, will always have
limitations. Two solutions for very different facets:

GNU multiprecision arithmetic library - <http://gmplib.org/> Coq Proof
Assistant - <http://www.lix.polytechnique.fr/coq/>

------
noonespecial
Computers suck at _some kinds_ of math. They excel at others. Mathemetician,
know thy tools.

------
akshar200
It is never possible to represent all the numebr in a fixed length binary
string.

~~~
SapphireSun
You can still store a symbolic representation of those numbers that you can't
represent though in limited cases (such as rational division) and write your
algorithms so that it doesn't truncate it in the worst possible way.

~~~
wingo
I feel compelled to mention that you could just use a language with a proper
numeric tower.

If the numbers that you input to an algorithm are exact, you get an exact
answer. If they are inexact, you get an inexact answer. 399 999 999 999 999 is
an exact number.

    
    
        guile> (- 399999999999 399999999998)
        $1 = 1

~~~
cousin_it
Another intriguing possibility is to represent all required numbers exactly,
even sqrt(2). It is possible with lazy evaluation: essentially a number is
represented by a function that computes the digits of its decimal expansion,
and arithmetic operations take two functions and return a third. Inefficient
but mind-blowing.

------
skwiddor
Because it's spelled "maths" :)

