1 /*-------------------------------------------------------------------------
4 * Definitions for the exact numeric data type of Postgres
6 * Original coding 1998, Jan Wieck. Heavily revised 2003, Tom Lane.
8 * Copyright (c) 1998-2019, PostgreSQL Global Development Group
10 * src/include/utils/numeric.h
12 *-------------------------------------------------------------------------
14 #ifndef _PG_NUMERIC_H_
15 #define _PG_NUMERIC_H_
20 * Limit on the precision (and hence scale) specifiable in a NUMERIC typmod.
21 * Note that the implementation limit on the length of a numeric value is
22 * much larger --- beware of what you use this for!
24 #define NUMERIC_MAX_PRECISION 1000
27 * Internal limits on the scales chosen for calculation results
29 #define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION
30 #define NUMERIC_MIN_DISPLAY_SCALE 0
32 #define NUMERIC_MAX_RESULT_SCALE (NUMERIC_MAX_PRECISION * 2)
35 * For inherently inexact calculations such as division and square root,
36 * we try to get at least this many significant digits; the idea is to
37 * deliver a result no worse than float8 would.
39 #define NUMERIC_MIN_SIG_DIGITS 16
41 /* The actual contents of Numeric are private to numeric.c */
43 typedef struct NumericData *Numeric;
46 * fmgr interface macros
49 #define DatumGetNumeric(X) ((Numeric) PG_DETOAST_DATUM(X))
50 #define DatumGetNumericCopy(X) ((Numeric) PG_DETOAST_DATUM_COPY(X))
51 #define NumericGetDatum(X) PointerGetDatum(X)
52 #define PG_GETARG_NUMERIC(n) DatumGetNumeric(PG_GETARG_DATUM(n))
53 #define PG_GETARG_NUMERIC_COPY(n) DatumGetNumericCopy(PG_GETARG_DATUM(n))
54 #define PG_RETURN_NUMERIC(x) return NumericGetDatum(x)
57 * Utility functions in numeric.c
59 extern bool numeric_is_nan(Numeric num);
60 int32 numeric_maximum_size(int32 typmod);
61 extern char *numeric_out_sci(Numeric num, int scale);
62 extern char *numeric_normalize(Numeric num);
64 extern Numeric numeric_add_opt_error(Numeric num1, Numeric num2,
66 extern Numeric numeric_sub_opt_error(Numeric num1, Numeric num2,
68 extern Numeric numeric_mul_opt_error(Numeric num1, Numeric num2,
70 extern Numeric numeric_div_opt_error(Numeric num1, Numeric num2,
72 extern Numeric numeric_mod_opt_error(Numeric num1, Numeric num2,
74 extern int32 numeric_int4_opt_error(Numeric num, bool *error);
76 #endif /* _PG_NUMERIC_H_ */