pycore_dtoa.h 1.6 KB

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