Bugs: Not a number nor a relative or a bread: NaN

Dec 29, 2006 17:28


If you were paying attention to the field of pseudoscience a couple of weeks ago you’ll remember the story of the maths teacher who revolutionised division by zero and without a by-your-leave was teaching it to secondary school pupils. Not only was he subverting the standard procedure of childhood education (by teaching his pet fantasies as the ( Read more... )

mathematics, programming, bugs, division by zero, guide, bad science, computer science

Leave a comment

Comments 4

zootm December 31 2006, 12:05:04 UTC
Well, technically mathematicians just haven't found a satisfactory result yet. Whether or not they actually will (no chance!) is up for debate, though. ;)

Reply

brokenhut January 1 2007, 18:30:08 UTC


It would contradict established properties for most numbering systems and algebras. Which would be bad.

Reply


codergnome January 25 2007, 14:38:47 UTC
It's not a programming language issue at all, it's a CPU issue. Integers can't divide-by-zero. That raises an interrupt in the CPU, which causes the kernel will kill the task (thus the "this program divided by zero!" error Windows pops up). Floating point values, however, can. It's defined (in IEEE 754, which virtually all CPUs follow), that x/0 = NaN for all x.

Technically, this is a "quiet NaN", which generates no errors when used in calculations. There is also a "signalling NaN", which does. Because division by zero results in a quiet NaN, sometimes programs might output a NaN if the programmer forgot to check for that case... but only if they were using floating point numbers.

Reply

brokenhut January 26 2007, 00:13:19 UTC


Are you suggesting that it would be a programming language issue without being a CPU issue? Like somehow programming languages use a different mathematics from processors?

As for the details about the difference between integers and floats - I haven't mentioned them yet, though I will get round to them at some point I imagine. They're less interesting that divide-by-zero errors. Ordinary users will come across the latter but don't need to know the difference with the former (except in the case of finance or science applications).

Writing it without going off at tangents is harder than you might think.

Reply


Leave a comment

Up