Scaled Integer for REALLY SMART people
prof_braino
Posts: 4,313
Back in the day, (half a day really) when I wrote applications on micros, there was NO Hardware Floating point. I would always ask the old geezers, why? They would laugh and say that REAL programmers seldom if ever need float, and its too expensive, slow and wasteful anyway. Being a kid, I ignored them and used my calculator.
BUT once in a while I took the time to do Scaled Integer math. This is also called fixed point math. The rounding errors are much more predicable than float, and the execution is usually faster than software floating point. Of course, on the prop we have tables built in to help with doing the floating point processing, so scaled integer might not be as vital as was in the olden times, but it is sometime useful.
You might have noticed a bunch of us are talking about ".. for Dummies" explanations for various topics. We're having fun with the Fourier for dummies in the other thread.
http://forums.parallax.com/showthread.php?t=127306
I thought this topic might be a stepping stone to work on that. Any takers?
BUT once in a while I took the time to do Scaled Integer math. This is also called fixed point math. The rounding errors are much more predicable than float, and the execution is usually faster than software floating point. Of course, on the prop we have tables built in to help with doing the floating point processing, so scaled integer might not be as vital as was in the olden times, but it is sometime useful.
You might have noticed a bunch of us are talking about ".. for Dummies" explanations for various topics. We're having fun with the Fourier for dummies in the other thread.
http://forums.parallax.com/showthread.php?t=127306
I thought this topic might be a stepping stone to work on that. Any takers?
Comments
The Prop with 32 bit signed integers is instantly more powerful than the BASIC stamp with its 16 bit limitation. 32 bits is a huge open territory for integer and fixed point math. The trick is always in the scaling. Calculations, multi-step especially, have to be arranged for minimal loss of precision. With floating point, most of those details are blissfully hidden, but can trip up the unwary. With fixed point, one has to think about the expected range of the variables and how that will play out with each step.
As with the Stamp, the ** operator is a huge helper when it comes to calculations that involve fractions (and double precision). The thing to watch out for in comparison to the Stamp is that the Prop math operators are almost all twos complement, respecting the sign negative or positive.
It's also kind of annoying that Spin doesn't have unsigned * and ** operators, but I think Chip might have run out of room when writing the interpreter.
Ada has full support for floating point as well as both ordinary fixed point and decimal fixed point arithmetic (decimal fixed point is good for implementing things like money - I think the defence department decided their language had to include this so all they could keep an accurate track of all their cost overruns ).
The really cool part is that you can declare your own floating or fixed point types at compile time - including the precision you want.
Here is a quick summary - check out the Floating Point, Fixed Point and Decimal Fixed Point types (about halfway down the page).
Ross.