fork download
  1. #include <stdio.h>
  2.  
  3.  
  4. int clkRate()
  5. {
  6. return 2000;
  7. }
  8.  
  9.  
  10.  
  11. const int MILLISECONDS_PER_SECOND = 1000;
  12. #define MS_TO_TICKS(ms) ( ( (float)(ms)/ MILLISECONDS_PER_SECOND) * clkRate() )
  13.  
  14.  
  15. void convertAndPrint(int ms)
  16. {
  17. int ticksInt;
  18. unsigned ticksUint;
  19. double ticksDbl;
  20. float ticksFlt;
  21.  
  22. ticksInt = MS_TO_TICKS(ms);
  23. ticksUint= MS_TO_TICKS(ms);
  24. ticksFlt = MS_TO_TICKS(ms);
  25. ticksDbl = MS_TO_TICKS(ms);
  26.  
  27. printf("Milliseconds: %i\n", ms);
  28. printf("Expected val: %i\n",ms*2);
  29. printf("Signed Int : %2i\n"
  30. "Unsigned Int: %2u\n"
  31. "Floating Pnt: %.13f\n"
  32. "Double Precn: %.13f\n"
  33. "Direct Macro: %.13f\n",ticksInt,ticksUint,ticksFlt, ticksDbl, MS_TO_TICKS(ms));
  34.  
  35. }
  36.  
  37. void weirdConversionDemo(void)
  38. {
  39.  
  40.  
  41. convertAndPrint(7);
  42. printf("\n\n\n\n");
  43. convertAndPrint(10);
  44.  
  45. }
  46.  
  47.  
  48. int main(void) {
  49. weirdConversionDemo();
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
Milliseconds: 7
Expected val: 14
Signed Int  : 14
Unsigned Int: 14
Floating Pnt: 14.0000000000000
Double Precn: 14.0000000000000
Direct Macro: 14.0000000000000




Milliseconds: 10
Expected val: 20
Signed Int  : 20
Unsigned Int: 20
Floating Pnt: 20.0000000000000
Double Precn: 20.0000000000000
Direct Macro: 20.0000000000000