Shop OBEX P1 Docs P2 Docs Learn Events
Scaled Integer for REALLY SMART people — Parallax Forums

Scaled Integer for REALLY SMART people

prof_brainoprof_braino Posts: 4,313
edited 2010-11-30 16:42 in Propeller 1
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?

Comments

  • LeonLeon Posts: 7,620
    edited 2010-11-30 05:18
    Fixed-point is used a lot, especially for DSP.
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-11-30 07:30
    Back in the day (which I half remember) we used integer math and wrote numerous programs. When we needed a float, we merely added a routine to do it. We had routines for specific dec places, math functions, searches and sorts, and all kinds of cool algorithms. 8-Bit Scaled Integer Math was very popular. In fact, my version of Tom Pittman's Tiny BASIC was grown to become very capable with these scaled extensions and mathematical algorithms, so it could be used for an early car traveling application, drawing maps, calculating distances, speeds, and mileage. As I remember though, the computer took up the entire seat next to me! If you kept your old issues of microcomputing, you'd see hundreds of these kinds of add-on software for the pickin'. Ironically, it's going to take some clever programming and time to reinvent the SPIN wheel.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-11-30 08:25
    Dr. Tracy Allen -- coolest PhD you'll ever meet -- is probably best qualified for this topic. He has used lots of integer math tricks with the BASIC Stamp and I'm sure with the Propeller that stuff is even more magical.
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2010-11-30 12:27
    Hey Jon, thanks for the coolness factor! I did manage to persist through grad school and to meet inspiring people and to entertain a few ideas. This list is a continuing inspiration, really smart people who collectively are REALLY SMART.

    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.
  • localrogerlocalroger Posts: 3,452
    edited 2010-11-30 16:29
    I program in several environments today where I have the option to use floating point, but I hardly ever do. Integer math is always much faster and more predictable. It takes more planning but it just plain works better. It's very annoying to work in something like Javascript which doesn't give you the option of forcing integer calculations.

    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.
  • RossHRossH Posts: 5,519
    edited 2010-11-30 16:42
    If you want to really give your brain a meltdown, check out Ada in this area.

    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 :lol:).

    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.
Sign In or Register to comment.