[G4] 2+2=4.0000001?
Amir 'CG' Caspi
cepheid at ssl.berkeley.edu
Thu Feb 26 20:24:08 PST 2004
On Thu, 26 Feb 2004, CJ Scaminaci wrote:
> Should being the key word ;) An integer operation still would have done
I am assuming no "funny business" like what Mathematica does, i.e.
representing numbers using custom memory objects. Then again, Mathematica
has essentially infinite precision, so... =)
> the job here. Whoever wrote the calculator program was lazy, and decided
> to float all the numbers. This kind of problem could have been avoided
Actually, I imagine that it was done this way to save memory and code.
Based purely on how *I* would write it, the calculator is written with
essentially two static registers - the number on the screen, and the
number in memory (which may also be the same as the number on the screen).
Therefore, when someone enters a number into the calculator, they are
essentially modifying the static register. If you now have to insert code
that decides whether to use the integer or floating-point register, you
now have to modify *ALL* of your code so that it chooses which register to
operate on, etc. This would make the code MUCH more cumbersome, more
likely to be buggy, and generally slower. Using a float at all times is
actually the more elegant way, code-wise.
--- Amir
More information about the G4
mailing list