BigDumbDinosaur wrote:
I think Curt was being facetious—no one I know does any pencil-and-paper calculations in anything other than decimal. :D
Facetious, yes, but not entirely so: there's a key kernel of very important truth in what I was saying, and a lesser kernel of perhaps (or perhaps not) interesting truth. More on the latter later.
wayfarer wrote:
I am referring to the floating point rounding error; my understanding is BCD never has this issue.
That is incorrect. BCD has rounding issues just as hexadecimal does, as does
any base. While the rounding errors will be
different rounding errors, they are still there.
Consider, for example, working in base 3. In that case, 1/10 = 0.1, and there is no rounding error at all. But in base 10, 1/3 = 0.333… which you will eventually have to round to a slightly different value, at least if you want to store it in memory or ever want your program to terminate.
If you're going to choose a base to try to avoid rounding errors as much as possible, but is still of reasonable size, base 60 is a good choice. (There's a reason that the ancient Babylonians used it.) But of course this assumes you're using it for your outside-the-computer work as well; if you're going to convert it to base 10 (or something equally ridiculous) outside the computer you're going to run into rounding issues again because of the conversion.
Base 60 is admittedly a bit annoying to use
everywhere, because of difficulties inherent in writing it, but there are definitely better bases to be chosen than 10, which is in general a pretty bad base for most things. This is why when I'm made King of the World my first decree will be that everything that was previously done in base 10 will in the future be done in base 12. (This will also have the beneficent side effect of bringing in world peace, because everybody will be too busy dealing with this change to prosecute wars and the like. Oh, and for the British who will now have to "undecimalise" their currency, sorry about that! You never should have changed!)
Quote:
I am planning to explore this further, I intend to do a lot of finite/discrete mathematics as I delve into 65xx ASM wherever possible.
Sounds to me as if you might be better off with bigints (high-precision or unlimited-precision integers) for that sort of thing, depending on exactly what you're doing. These, again tend to work best in binary representation internally, though, offering some memory savings and considerably more speed. In which case you might consider (also depending on what you're doing) just using hex representation externally, since it's essentially isomorphic. You can get a sense of the costs of conversion from
a bit of 6502 bigint code I wrote a while back and its
unit tests.
Remember, your desire to work in base 10 is, from a mathematical point of view, completely arbitrary. You're not going to get better answers in that base; you're probably going to get worse ones than several other more sensible bases.
Quote:
It is such a part of 65xx at this point, I think it is worth exploring the efficiency of BCD vs traditional math operations for any serious maths library built... :?:
It's been explored; that's a reason that for a long time we've done most maths in binary when using binary computers.
BigDumbDinosaur wrote:
I think Curt was being facetious—no one I know does any pencil-and-paper calculations in anything other than decimal. :D
Back to this! While admittedly I no longer do many calculations using an actual pencil and paper (though I certainly did back in the early '80s before I got my TI Programmer and, later, HP-16C!), I still do the equivalent all the time at my command line. I have a little wrapper around the Unix bc(1) program (an infinite precision calculator) that lets me easily specify hex input and/or output, and so I quite frequently am doing things like `c -Hh ffe2-c8` (which spits out `FF1A`).
Now admittedly I'm doing only integer calculations these days, but part of the reason for that is that the only floating point I've been working with lately has been with the MSX-BASIC representations, where MS had switched to BCD significands. But I'm sure I'll have use of bc(1)'s floating point support (which works fine: `c -Hh 5a.29/3` gives `1E.0D9`) when I get around to writing my own floating point libraries.