system.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: system.h,v 1.2 1999/01/19 04:41:43 jgg Exp $
  4. /* ######################################################################
  5. System Header - Usefull private definitions
  6. This source is placed in the Public Domain, do with it what you will
  7. It was originally written by Brian C. White.
  8. ##################################################################### */
  9. /*}}}*/
  10. // Private header
  11. #ifndef SYSTEM_H
  12. #define SYSTEM_H
  13. // MIN_VAL(SINT16) will return -0x8000 and MAX_VAL(SINT16) = 0x7FFF
  14. #define MIN_VAL(t) (((t)(-1) > 0) ? (t)( 0) : (t)(((1L<<(sizeof(t)*8-1)) )))
  15. #define MAX_VAL(t) (((t)(-1) > 0) ? (t)(-1) : (t)(((1L<<(sizeof(t)*8-1))-1)))
  16. // Min/Max functions
  17. #if defined(__HIGHC__)
  18. #define MIN(x,y) _min(x,y)
  19. #define MAX(x,y) _max(x,y)
  20. #endif
  21. /* Templates tend to mess up existing code that uses min/max because of the
  22. strict matching requirements */
  23. #if !defined(MIN)
  24. #define MIN(A,B) ((A) < (B)?(A):(B))
  25. #define MAX(A,B) ((A) > (B)?(A):(B))
  26. #endif
  27. /* Bound functions, bound will return the value b within the limits a-c
  28. bounv will change b so that it is within the limits of a-c. */
  29. #define _bound(a,b,c) MIN(c,MAX(b,a))
  30. #define _boundv(a,b,c) b = _bound(a,b,c)
  31. #define ABS(a) (((a) < (0)) ?-(a) : (a))
  32. /* Usefull count macro, use on an array of things and it will return the
  33. number of items in the array */
  34. #define _count(a) (sizeof(a)/sizeof(a[0]))
  35. // Flag Macros
  36. #define FLAG(f) (1L << (f))
  37. #define SETFLAG(v,f) ((v) |= FLAG(f))
  38. #define CLRFLAG(v,f) ((v) &=~FLAG(f))
  39. #define CHKFLAG(v,f) ((v) & FLAG(f) ? true : false)
  40. #endif