FIXED POINT EXAMPLE ------------------- #pragma chip PIC16C73 #include "math24x.h" uns16 data; // 16 bit unsigned integer fixed16_8 tx, av, mg, a, vx, prev, kp; // 24 bit fixed point void main(void) { vx = 3.127; tx += data; // automatic type cast data = kp; // assign integer part if ( tx < 0) tx = -tx; // make positive av = tx/20.0; mg = av * 1.25; a = mg * 0.98; // 0.980469: error on constant: 0.000478 prev = vx; vx = a/5.0 + prev; kp = vx * 0.036; // 0.03515626: error on constant: 0.024 kp = vx / (1.0/0.036); // 27.7773437 error on constant: 0.0000156 } // CODE: 274 instructions including library of 130 instructions FLOATING POINT EXAMPLE ---------------------- // CODE: 635 instructions including library of 470 instructions // The code is identical to the above fixed point example // to enable code size comparison #pragma chip PIC16C73 #include "math24f.h" uns16 data; // 16 bit unsigned integer float tx, av, mg, a, vx, prev, kp; // 24 bit floating point void main(void) { InitFpFlags(); // enable rounding as default vx = 3.127; tx += data; // automatic type cast data = kp; // assign integer part if ( tx < 0) tx = -tx; // make positive av = tx/20.0; mg = av * 1.25; a = mg * 0.98; prev = vx; vx = a/5.0 + prev; kp = vx * 0.036; kp = vx / (1.0/0.036); }