numeric.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*-------------------------------------------------------------------------
  2. *
  3. * numeric.h
  4. * Definitions for the exact numeric data type of Postgres
  5. *
  6. * Original coding 1998, Jan Wieck. Heavily revised 2003, Tom Lane.
  7. *
  8. * Copyright (c) 1998-2016, PostgreSQL Global Development Group
  9. *
  10. * src/include/utils/numeric.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef _PG_NUMERIC_H_
  15. #define _PG_NUMERIC_H_
  16. #include "fmgr.h"
  17. /*
  18. * Limit on the precision (and hence scale) specifiable in a NUMERIC typmod.
  19. * Note that the implementation limit on the length of a numeric value is
  20. * much larger --- beware of what you use this for!
  21. */
  22. #define NUMERIC_MAX_PRECISION 1000
  23. /*
  24. * Internal limits on the scales chosen for calculation results
  25. */
  26. #define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION
  27. #define NUMERIC_MIN_DISPLAY_SCALE 0
  28. #define NUMERIC_MAX_RESULT_SCALE (NUMERIC_MAX_PRECISION * 2)
  29. /*
  30. * For inherently inexact calculations such as division and square root,
  31. * we try to get at least this many significant digits; the idea is to
  32. * deliver a result no worse than float8 would.
  33. */
  34. #define NUMERIC_MIN_SIG_DIGITS 16
  35. /* The actual contents of Numeric are private to numeric.c */
  36. struct NumericData;
  37. typedef struct NumericData *Numeric;
  38. /*
  39. * fmgr interface macros
  40. */
  41. #define DatumGetNumeric(X) ((Numeric) PG_DETOAST_DATUM(X))
  42. #define DatumGetNumericCopy(X) ((Numeric) PG_DETOAST_DATUM_COPY(X))
  43. #define NumericGetDatum(X) PointerGetDatum(X)
  44. #define PG_GETARG_NUMERIC(n) DatumGetNumeric(PG_GETARG_DATUM(n))
  45. #define PG_GETARG_NUMERIC_COPY(n) DatumGetNumericCopy(PG_GETARG_DATUM(n))
  46. #define PG_RETURN_NUMERIC(x) return NumericGetDatum(x)
  47. /*
  48. * Utility functions in numeric.c
  49. */
  50. extern bool numeric_is_nan(Numeric num);
  51. int32 numeric_maximum_size(int32 typmod);
  52. extern char *numeric_out_sci(Numeric num, int scale);
  53. extern char *numeric_normalize(Numeric num);
  54. #endif /* _PG_NUMERIC_H_ */