[Sussex] Challenge
Geoff Teale
Geoff.Teale at claybrook.co.uk
Thu May 1 08:41:01 UTC 2003
Mark wrote:
-----------
<snippage>
> Not at all. Both Steve and I have given a model for
> expressing 0.1 (decimal) in
> a way that's capable of manipulation on a binary computer.
>
>
> How you represent numbers on computers is a big topic in its
> own right... and
> we've not sidestepped that - we've both tackled it head on
> and given a concrete
> example of why most modern languages DON'T simply use 0=0,
> 01=1, 10=2, 11=3,
> 100=4 as their only way of representing numbers.
Now, hold on there just a second. You are right that what both you and
Steve gave were valid representations that _could_ be used to solve this
problem. However, the second part of that second statement, whilst not
untrue, could certainly be misleading to the inexperienced developer.
While it is true that some languages have complex data types that don't
directly use this methodolgy (though the underlying data is stored this way
as integers), most modern languages [C, C++, Fortran, Java, Pascal, Perl,
Python] _DO_ use these meachanism as their primary means of storing numbers
and very few programmers dream of using anything else outside of the
requirement for complex numbers. Consider for a moment how slow computation
would be if every time there was a risk of generating the number 0.1 we
shifted all of our floating point operations out of hardware and into
software based around complex storage of multiple integers! Almost all
hardware today uses IEEE-754 floating point arithmetic, and almost all
platforms map IEEE-754 to "double precision" or "float" in programming
languages. IEEE-754 doubles contain 53 bits of precision, so on input the
computer strives to convert 0.1 to the closest fraction it can of the form
J/2**N where J is an integer containing exactly 53 bits.
In short, knowledgeable programmers worry about it as and when necessary and
apply fudge topping rather than hang a bag off of it. Ignorant programmers
are probably using VB where the fudge topping has already been added for you
- this of course is why VB tastes nice at first but if you use it too much
it makes you feel sick. Too much fudge ;)
> My version majored on mathematical rigout. Steve's majored on
> programming
> expressability.
Agreed
> I don't think that either was a fudge at all.
Well, your solutions give you two choices for implementation :
1, Developer a new data type based on multi-part representation of floating
point variables and then develop all the FLOP's on top of them. This is
viable, but deeply inefficient. I would generally consider that if you are
reimplimenting hardware functions in software then you're going to have to
give me a heck of a good reason why or I'm going to suspect you are hanging
a bag on the side of the hardware platform - a pretty major step.
2, Allow the language to resolve the equations, this is not valid because it
still results in the problem in representing 0.1 in binary (in the hardware)
using IEEE-754.
--
GJT
Free Software, Free Society.
http://www.fsf.org http://www.gnu.org
The above information is confidential to the addressee and may be privileged. Unauthorised access and use is prohibited.
Internet communications are not secure and therefore this Company does not accept legal responsibility for the contents of this message.
If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful.
Claybrook Computing Limited is a subsidiary of Claybrook Computing (Holdings) Limited
Registered Office: Abbey House. 282 Farnborough Road, Farnborough, Hampshire GU14 7NJ
Registered in England and Wales No 1287205
A Hogg Robinson plc company
More information about the Sussex
mailing list