BigDumbDinosaur wrote:
GARTHWILSON wrote:
Hexadecimal works just fine though if you use fixed-point...In the internal representation, $.99 times two is still $1.98, $2.49 + $14.40 is still $16.89, etc...
How does it work out with .01 × .02?
I'll assume only one of those is a dollar amount, so you don't have dollars-squared. The representation of the other one is idependent. In any case, the programmer keeps track of how many places to move the decimal point over (like we learned to do on paper in 3rd grade) when it's time for human-readable output, or, in the case of scaled-integer and not merely fixed-point, multiplying or dividing by a non-round number, like there being 10,430 counts in a radian angle measure or 182 counts in a degree if the whole circle is 65,536 counts which works out really nice for trig.
That matter of the angles in particular is a situation where it doesn't matter if you treat the numbers as signed or unsigned, because for example 359° is the same as -1°.
Quote:
The one potential problem I do see with using scaled, fixed-point hex is range.
You could scale it in floating point too, still representing a cent by 1 instead of .01, to avoid the accuracy problem.
As for the big numbers (Julian dates etc.), adding bytes for more precision, Dartht33bagger, is easy in integer work, using the C flag. (I had to get back to the topic!
) The real-time clock (RTC) on my workbench computer is run in software, on interrupts (NMI), and I keep a 32-bit count of centiseconds, giving me 10ms resolution with a count that rolls over in a little over 16 months which is no problem since I've never needed it powered for more that a couple of weeks continuously. If I wanted it to go thousands of years, I would have to use 48 bits. (There's also another set of bytes that I make roll over at 100 for centiseconds, 60 for seconds and minutes, and 24 for hours, and then the right number of days for each month.)
If you want to keep track of tenths of a penny on something like the national debt though, you'll need at least 17 decimal digits any way you approach it.
Quote:
There is no free lunch with this, I'm afraid.
As is always the case.