The nought point threeness of 0.3
So far so good, but there’s a mildly surprising aspect to these two functions. They don’t return numbers. Instead they return character strings – text to you and me. Think about it some more and you realise that yes you really do want the character string “0.3″ rather than some number 0.3. After all, the computer program does not usually manipulate a data structure that represents three tenths precisely. Instead, it uses a truncated binary representation that fits the machine architecture better. That’s why, given a chance, it might print out 0.29999999999987 instead of 0.3.
This gets one thinking about the huge difference between the machine’s internal representation of a number – the working model which can be manipulated arithmetically – and the external representation – the set of characters to be sent to a display device.
The machine usually represents 0.3 in an approximate binary form simply because that’s the fastest thing to manipulate if all you want is answers to 13 significant figures or so. But if you really wanted to do rational arithmetic precisely, then fine, the machine can use a better data structure – one that stores the integers 3 and 10 separately – and achieve perfect precision. We’ve all played with calculators that can add fractions perfectly after all.
The interesting thing about this is that internally, the number we know as 0.3 has to be represented in different ways for different purposes. It’s an object that contains both data – the binary floating point string, the 3, the 10 – and algorithms. Provided we can capture the essence of 0.3 in these objects in a finite amount of computer memory and processing time we have a precise internal model of the number.
Now what about a transcendental number? Can a computer hold a perfect model of pi? How big an object would the representation be? Would it be finite? Can we ask for ‘perfect’ or must we make do with ‘practical’? Tricky one…