fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #ifndef M_PI
  4. // Stolen from /usr/include/math.h
  5. #define M_PI 3.14159265358979323846
  6. #endif
  7.  
  8. #define DEGREES_TO_RADIANS(d) ((d) *(float)M_PI / 180.0f)
  9. #define RADIANS_TO_DEGREES(r) ((r) *180.0f / (float)M_PI)
  10. #define RADIANS_TO_POSITION(r) (DEGREES_TO_POSITION(RADIANS_TO_DEGREES((r))))
  11. #define POSITION_TO_RADIANS(p) (DEGREES_TO_RADIANS(POSITION_TO_DEGREES((p))))
  12.  
  13. #define THIRTY_DEGREES_IN_COUNTS (100000)
  14.  
  15. /* Define a generalized fractional multiply */
  16. #define FRMULQ(a, b, q) (((a) * (b)) >> (q))
  17. #define RAY_TIME_US (1.f / 0.48f)
  18.  
  19. static inline float POSITION_TO_DEGREES(float position)
  20. {
  21. return position * (30.0f / THIRTY_DEGREES_IN_COUNTS);
  22. }
  23.  
  24. int main(void) {
  25. // your code goes here
  26. const float first_ray_pos = 22091.126953;
  27. const int32_t distance_from_first_ray = 1;
  28. const int32_t vel = -19;
  29. const float vel_adder = (distance_from_first_ray * vel * RAY_TIME_US / 10.f);
  30. const float position = first_ray_pos + vel_adder;
  31. const float el_radians = POSITION_TO_RADIANS(position);
  32. printf("vel_adder=%f, position = %f, el_radians=%f", vel_adder, position, el_radians);
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 5328KB
stdin
Standard input is empty
stdout
vel_adder=-3.958333, position = 22087.167969, el_radians=0.115648