pycore_dtoa.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef Py_INTERNAL_DTOA_H
  2. #define Py_INTERNAL_DTOA_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #ifndef Py_BUILD_CORE
  7. # error "this header requires Py_BUILD_CORE define"
  8. #endif
  9. #include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
  10. typedef uint32_t ULong;
  11. struct
  12. Bigint {
  13. struct Bigint *next;
  14. int k, maxwds, sign, wds;
  15. ULong x[1];
  16. };
  17. #if defined(Py_USING_MEMORY_DEBUGGER) || _PY_SHORT_FLOAT_REPR == 0
  18. struct _dtoa_state {
  19. int _not_used;
  20. };
  21. #define _dtoa_state_INIT(INTERP) \
  22. {0}
  23. #else // !Py_USING_MEMORY_DEBUGGER && _PY_SHORT_FLOAT_REPR != 0
  24. /* The size of the Bigint freelist */
  25. #define Bigint_Kmax 7
  26. #ifndef PRIVATE_MEM
  27. #define PRIVATE_MEM 2304
  28. #endif
  29. #define Bigint_PREALLOC_SIZE \
  30. ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double))
  31. struct _dtoa_state {
  32. /* p5s is a linked list of powers of 5 of the form 5**(2**i), i >= 2 */
  33. // XXX This should be freed during runtime fini.
  34. struct Bigint *p5s;
  35. struct Bigint *freelist[Bigint_Kmax+1];
  36. double preallocated[Bigint_PREALLOC_SIZE];
  37. double *preallocated_next;
  38. };
  39. #define _dtoa_state_INIT(INTERP) \
  40. { \
  41. .preallocated_next = (INTERP)->dtoa.preallocated, \
  42. }
  43. #endif // !Py_USING_MEMORY_DEBUGGER
  44. /* These functions are used by modules compiled as C extension like math:
  45. they must be exported. */
  46. PyAPI_FUNC(double) _Py_dg_strtod(const char *str, char **ptr);
  47. PyAPI_FUNC(char *) _Py_dg_dtoa(double d, int mode, int ndigits,
  48. int *decpt, int *sign, char **rve);
  49. PyAPI_FUNC(void) _Py_dg_freedtoa(char *s);
  50. #ifdef __cplusplus
  51. }
  52. #endif
  53. #endif /* !Py_INTERNAL_DTOA_H */