stdint.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #if defined(_MSC_VER)
  3. typedef signed char int8_t;
  4. typedef signed short int16_t;
  5. typedef signed int int32_t;
  6. typedef signed long long int64_t;
  7. typedef int64_t intmax_t;
  8. #if defined(_WIN64)
  9. typedef int64_t intptr_t;
  10. #else
  11. typedef int32_t intptr_t;
  12. #endif
  13. typedef unsigned char uint8_t;
  14. typedef unsigned short uint16_t;
  15. typedef unsigned int uint32_t;
  16. typedef unsigned long long uint64_t;
  17. typedef uint64_t uintmax_t;
  18. #if defined(_WIN64)
  19. typedef uint64_t uintptr_t;
  20. #else
  21. typedef uint32_t uintptr_t;
  22. #endif
  23. #else
  24. #include <stdint.h>
  25. #endif
  26. //note: (u)intmax actually mean it: use as many bits as is possible
  27. #if defined(__SIZEOF_INT128__)
  28. using int128_t = signed __int128;
  29. using uint128_t = unsigned __int128;
  30. #define INTMAX_BITS 128
  31. using intmax = int128_t;
  32. using uintmax = uint128_t;
  33. #else
  34. #define INTMAX_BITS 64
  35. using intmax = intmax_t;
  36. using uintmax = uintmax_t;
  37. #endif
  38. using intptr = intptr_t;
  39. using uintptr = uintptr_t;
  40. using float32_t = float;
  41. using float64_t = double;
  42. //note: long double size is not reliable across platforms
  43. //using float80_t = long double;
  44. static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" );
  45. static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size");
  46. static_assert(sizeof(int32_t) == 4, "int32_t is not of the correct size");
  47. static_assert(sizeof(int64_t) == 8, "int64_t is not of the correct size");
  48. static_assert(sizeof(uint8_t) == 1, "int8_t is not of the correct size" );
  49. static_assert(sizeof(uint16_t) == 2, "int16_t is not of the correct size");
  50. static_assert(sizeof(uint32_t) == 4, "int32_t is not of the correct size");
  51. static_assert(sizeof(uint64_t) == 8, "int64_t is not of the correct size");
  52. static_assert(sizeof(float) >= 4, "float32_t is not of the correct size");
  53. static_assert(sizeof(double) >= 8, "float64_t is not of the correct size");
  54. //static_assert(sizeof(long double) >= 10, "float80_t is not of the correct size");
  55. using uint = unsigned int;
  56. using real32_t = float;
  57. using real64_t = double;