fp-test2.c
1 | #include <stdio.h>
| 2 | #include <stdlib.h>
| 3 | #include <math.h>
| 4 |
| 5 | #define FIXEDPT_WBITS 16
| 6 | #include "fixedptc.h"
| 7 |
| 8 | #define Q16(f) (int)((f) * (1<<16))
| 9 |
| 10 | int main(int argc, char **argv)
| 11 | {
| 12 | int a, b, c;
| 13 | float result_1;
| 14 | float result_2;
| 15 |
| 16 | // float calculation
| 17 | result_1 = pow(2.9f, 6.24f);
| 18 |
| 19 | // fixpoint calculation
| 20 | a = Q16(2.9f);
| 21 | b = Q16(6.24f);
| 22 | c = fixedpt_pow(a, b);
| 23 |
| 24 | // convert to float for convenient output
| 25 | result_2 = (float)(c)/(float)(1<<16);
| 26 |
| 27 | printf("float: %.6f\n", result_1);
| 28 | printf("fixpoint: %.6f\n", result_2);
| 29 |
| 30 | return 0;
| 31 | }
|
|