number.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*====================================================================*
  2. *
  3. * number.h - numeric conversion definitions and declarations;
  4. *
  5. * Motley Tools by Charles Maier;
  6. * Copyright 2001-2006 by Charles Maier Associates;
  7. * Licensed under the Internet Software Consortium License;
  8. *
  9. *--------------------------------------------------------------------*/
  10. #ifndef NUMBER_HEADER
  11. #define NUMBER_HEADER
  12. /*====================================================================*
  13. * system header files;
  14. *--------------------------------------------------------------------*/
  15. #include <stdio.h>
  16. #include <stdint.h>
  17. #include <stddef.h>
  18. /*====================================================================*
  19. * numeric converson sizes and limits;
  20. *--------------------------------------------------------------------*/
  21. #define RADIX_BIN 2
  22. #define RADIX_OCT 8
  23. #define RADIX_DEC 10
  24. #define RADIX_HEX 16
  25. #define RADIX_MIN 2
  26. #define RADIX_MAX 36
  27. #define BIN_DIGITS 8
  28. #define DEC_DIGITS 3
  29. #define OCT_DIGITS 3
  30. #define HEX_DIGITS 2
  31. #define IPv4_SIZE 4
  32. #define IPv6_SIZE 16
  33. /*====================================================================*
  34. * numeric conversion strings;
  35. *--------------------------------------------------------------------*/
  36. #define DIGITS_BIN "01"
  37. #define DIGITS_OCT "01234567"
  38. #define DIGITS_DEC "0123456789"
  39. #define DIGITS_HEX "0123456789ABCDEF"
  40. #define DIGITS_ALL "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  41. /*====================================================================*
  42. * numeric string extenders;
  43. *--------------------------------------------------------------------*/
  44. #define BIN_EXTENDER '-'
  45. #define DEC_EXTENDER '.'
  46. #define HEX_EXTENDER ':'
  47. /*====================================================================*
  48. *
  49. *--------------------------------------------------------------------*/
  50. #define isodd(n) (((n)&(1)) != 0)
  51. #define iseven(n) (((n)&(1)) == 0)
  52. /*====================================================================*
  53. *
  54. *--------------------------------------------------------------------*/
  55. uint64_t QCASRand (uint32_t seed);
  56. uint32_t QCARand ();
  57. /*====================================================================*
  58. *
  59. *--------------------------------------------------------------------*/
  60. uint64_t basespec (char const * string, unsigned base, unsigned size);
  61. uint64_t uintspec (char const * string, uint64_t minimum, uint64_t maximum);
  62. uint64_t tonumber (char const * string, uint64_t minimum, uint64_t maximum, uint64_t nominal);
  63. signed sintspec (char const *string, signed number);
  64. unsigned totruth (char const *string, signed fail);
  65. unsigned todigit (unsigned c);
  66. /*====================================================================*
  67. * end definitions;
  68. *--------------------------------------------------------------------*/
  69. #endif