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-2013, PostgreSQL Global Development Group
10 * src/include/utils/numeric.h
12 *-------------------------------------------------------------------------
14 #ifndef _PG_NUMERIC_H_
15 #define _PG_NUMERIC_H_
20 * Hardcoded precision limit - arbitrary, but must be small enough that
21 * dscale values will fit in 14 bits.
23 #define NUMERIC_MAX_PRECISION 1000
26 * Internal limits on the scales chosen for calculation results
28 #define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION
29 #define NUMERIC_MIN_DISPLAY_SCALE 0
31 #define NUMERIC_MAX_RESULT_SCALE (NUMERIC_MAX_PRECISION * 2)
34 * For inherently inexact calculations such as division and square root,
35 * we try to get at least this many significant digits; the idea is to
36 * deliver a result no worse than float8 would.
38 #define NUMERIC_MIN_SIG_DIGITS 16
40 /* The actual contents of Numeric are private to numeric.c */
42 typedef struct NumericData *Numeric;
45 * fmgr interface macros
48 #define DatumGetNumeric(X) ((Numeric) PG_DETOAST_DATUM(X))
49 #define DatumGetNumericCopy(X) ((Numeric) PG_DETOAST_DATUM_COPY(X))
50 #define NumericGetDatum(X) PointerGetDatum(X)
51 #define PG_GETARG_NUMERIC(n) DatumGetNumeric(PG_GETARG_DATUM(n))
52 #define PG_GETARG_NUMERIC_COPY(n) DatumGetNumericCopy(PG_GETARG_DATUM(n))
53 #define PG_RETURN_NUMERIC(x) return NumericGetDatum(x)
56 * Utility functions in numeric.c
58 extern bool numeric_is_nan(Numeric num);
59 int32 numeric_maximum_size(int32 typmod);
60 extern char *numeric_out_sci(Numeric num, int scale);
62 #endif /* _PG_NUMERIC_H_ */