fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. typedef int32_t Q16;
  5.  
  6. Q16 floatToQ16(float in)
  7. {
  8. return in*(1<<16);
  9. }
  10. float q16ToFlaot(Q16 in)
  11. {
  12. return (float)in/(1<<16);
  13. }
  14. Q16 q16mul(Q16 a, Q16 b)
  15. {
  16. return (int64_t)a*b>>16;
  17. }
  18. Q16 q16pol(Q16 a, Q16 b, Q16 c, Q16 x)
  19. {
  20. return q16mul(a, q16mul(q16mul(x, x), x))
  21. + q16mul(b,q16mul(x,x))
  22. + q16mul(c, x);
  23. }
  24. int main(void) {
  25. printf("2*20.123^3+3*20.123^2+4*20.123=%f\n",
  26. q16ToFlaot(q16pol(floatToQ16(2.0f),
  27. floatToQ16(3.0f),
  28. floatToQ16(4.0f),
  29. floatToQ16(20.123f))));
  30. // your code goes here
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
2*20.123^3+3*20.123^2+4*20.123=17592.279297