defines.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except
  4. in compliance with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2016
  6. All rights reserved.
  7. */
  8. #ifndef DSI_DEFINES_H
  9. #define DSI_DEFINES_H
  10. #include "types.h"
  11. //////////////////////////////////////////////////////////////////////////////////
  12. // Public Definitions
  13. //////////////////////////////////////////////////////////////////////////////////
  14. #define KELVIN 273.15F
  15. #define G 9.80665F // m/s2
  16. #define PI 3.14159265359F
  17. #define RADTODEG(x) ((x) * 360.0F / (2.0F * PI))
  18. #define DEGTORAD(x) ((x) * (2.0F * PI) / 360.0F)
  19. #define CTOK(x) ((x) + KELVIN)
  20. #define KTOC(x) ((x) - KELVIN)
  21. #define MIN(x, y) (((x) < (y)) ? (x) : (y))
  22. #define MAX(x, y) (((x) > (y)) ? (x) : (y))
  23. #define SQR(x) ((x) * (x))
  24. #define UINTDIV(x, y) (((x) + (y) / 2) / (y)) // Unsigned integer division, x / y rounded to the nearest integer
  25. #define ROUND_BIAS(x) ((x) < 0 ? -0.5F : 0.5F)
  26. #define ROUND_FLOAT(x) ((x) + ROUND_BIAS(x))
  27. // The following macro computes offset (in bytes) of a member in a
  28. // structure. This compiles to a constant if a constant member is
  29. // supplied as arg.
  30. #define STRUCT_OFFSET(MEMBER, STRUCT_TYPE) ( ((UCHAR *) &(((STRUCT_TYPE *) NULL)->MEMBER)) - ((UCHAR *) (NULL)) )
  31. #endif // defined(DSI_DEFINES_H)