4 ms·
Coding Horror: Why Do Computers Suck at Math?
- csomar 18y agoThe 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 18y agoThe new calculator uses arbitrary-precision arithmetic, I think.
- khandekars 18y agoComputers 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/ http://gmplib.org/ Coq Proof Assistant - http://www.lix.polytechnique.fr/coq/ http://www.lix.polytechnique.fr/coq/
- akshar200 18y agoIt is never possible to represent all the numebr in a fixed length binary string.
- SapphireSun 18y agoYou 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 18y agoI 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
- tl 18y ago~$ sbcl * (- 399999999999999 399999999999998) 1 * (- 12.52 12.51) 0.010000229 * (* 850 77.1) 65535.0
- cousin_it 18y agoAnother 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.
- noonespecial 18y agoComputers suck at some kinds of math. They excel at others. Mathemetician, know thy tools.
- michael_dorfman 18y agoAs 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.
- pookleblinky 18y ago"Computers are awesome, yes, but they aren't infinite.. yet." No. Just no.
- gaius 18y agoHey, that's a bit harsh. He's a blogger, not a programmer.
- vicaya 18y agoHe's the main developer of stackoverflow, which I think is pretty good compared with many other sites :)
- jules 18y ago> 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?
- lena 18y agoThis 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?
- RiderOfGiraffes 18y agoThis 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.
- skwiddor 18y agoBecause it's spelled "maths" :)