numbers.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <contrib/libs/openssl/redef.h>
  2. /*
  3. * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
  4. *
  5. * Licensed under the OpenSSL license (the "License"). You may not use
  6. * this file except in compliance with the License. You can obtain a copy
  7. * in the file LICENSE in the source distribution or at
  8. * https://www.openssl.org/source/license.html
  9. */
  10. #ifndef OSSL_INTERNAL_NUMBERS_H
  11. # define OSSL_INTERNAL_NUMBERS_H
  12. # include <limits.h>
  13. # if (-1 & 3) == 0x03 /* Two's complement */
  14. # define __MAXUINT__(T) ((T) -1)
  15. # define __MAXINT__(T) ((T) ((((T) 1) << ((sizeof(T) * CHAR_BIT) - 1)) ^ __MAXUINT__(T)))
  16. # define __MININT__(T) (-__MAXINT__(T) - 1)
  17. # elif (-1 & 3) == 0x02 /* One's complement */
  18. # define __MAXUINT__(T) (((T) -1) + 1)
  19. # define __MAXINT__(T) ((T) ((((T) 1) << ((sizeof(T) * CHAR_BIT) - 1)) ^ __MAXUINT__(T)))
  20. # define __MININT__(T) (-__MAXINT__(T))
  21. # elif (-1 & 3) == 0x01 /* Sign/magnitude */
  22. # define __MAXINT__(T) ((T) (((((T) 1) << ((sizeof(T) * CHAR_BIT) - 2)) - 1) | (((T) 1) << ((sizeof(T) * CHAR_BIT) - 2))))
  23. # define __MAXUINT__(T) ((T) (__MAXINT__(T) | (((T) 1) << ((sizeof(T) * CHAR_BIT) - 1))))
  24. # define __MININT__(T) (-__MAXINT__(T))
  25. # else
  26. # error "do not know the integer encoding on this architecture"
  27. # endif
  28. # ifndef INT8_MAX
  29. # define INT8_MIN __MININT__(int8_t)
  30. # define INT8_MAX __MAXINT__(int8_t)
  31. # define UINT8_MAX __MAXUINT__(uint8_t)
  32. # endif
  33. # ifndef INT16_MAX
  34. # define INT16_MIN __MININT__(int16_t)
  35. # define INT16_MAX __MAXINT__(int16_t)
  36. # define UINT16_MAX __MAXUINT__(uint16_t)
  37. # endif
  38. # ifndef INT32_MAX
  39. # define INT32_MIN __MININT__(int32_t)
  40. # define INT32_MAX __MAXINT__(int32_t)
  41. # define UINT32_MAX __MAXUINT__(uint32_t)
  42. # endif
  43. # ifndef INT64_MAX
  44. # define INT64_MIN __MININT__(int64_t)
  45. # define INT64_MAX __MAXINT__(int64_t)
  46. # define UINT64_MAX __MAXUINT__(uint64_t)
  47. # endif
  48. # ifndef SIZE_MAX
  49. # define SIZE_MAX __MAXUINT__(size_t)
  50. # endif
  51. #endif