
"Martin Bonner" <Martin.Bonner@pi-shurlok.com> writes:
I like the ability to specify the number of bits either side of the decimal point, but this does get in the way for doing the math functions --- you need a table with magic numbers in at the appropriate precision for exp and sin/cos.
Presumably the tables could be computed at run time once per type.
Yes, but that would add to the app startup cost, or make the first math function call *very* expensive. The arctan table (for sin and cos) has 30 entries, and the log tables used for exp total 91 entries. 30 calls to atan and 91 calls to log can take a while.
If you were doing this in a loop, yes, but as a single, one time, startup cost? Even if each call to atan/log takes a microsecond, and you use all 64 different precisions, that's *still* only a few milliseconds on the startup - who is going to care?
Um. If you are doing this in an embedded 16-bit processor (which is just the sort of place that fixed point often /is/ useful), that microsecond might be a bit optimistic - and you would really want the constants in ROM not RAM.
Exactly. I wrote my fixed point class for code that ran on an ARM processor. The version of exp in the C library (for doubles) takes 600 microseconds on that target. Just the one set of tables would be an extra 60ms at startup, and 64 sets would cause a delay of over 3 seconds --- quite noticeable. For a 16-bit target, I would be surprised if anyone was using 64 bit fixed point, and if you have less precision you need fewer table entries. Then again, I expect 16 bit embedded CPUs to be rather slow in calculating log. Of course, it wouldn't take too much effort to write a program to spew out the tables for each and every possible set of precisions. The generated source files could be then be compiled as normal, and the compiler could dutifully put the values in ROM as desired. Anthony -- Anthony Williams Just Software Solutions Ltd - http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL