]> granicus.if.org Git - postgresql/blob - src/include/utils/numeric.h
pgindent run before PG 9.1 beta 1.
[postgresql] / src / include / utils / numeric.h
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-2011, 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
17 #include "fmgr.h"
18
19 /*
20  * Hardcoded precision limit - arbitrary, but must be small enough that
21  * dscale values will fit in 14 bits.
22  */
23 #define NUMERIC_MAX_PRECISION           1000
24
25 /*
26  * Internal limits on the scales chosen for calculation results
27  */
28 #define NUMERIC_MAX_DISPLAY_SCALE       NUMERIC_MAX_PRECISION
29 #define NUMERIC_MIN_DISPLAY_SCALE       0
30
31 #define NUMERIC_MAX_RESULT_SCALE        (NUMERIC_MAX_PRECISION * 2)
32
33 /*
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.
37  */
38 #define NUMERIC_MIN_SIG_DIGITS          16
39
40 /* The actual contents of Numeric are private to numeric.c */
41 struct NumericData;
42 typedef struct NumericData *Numeric;
43
44 /*
45  * fmgr interface macros
46  */
47
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)
54
55 /*
56  * Utility functions in numeric.c
57  */
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);
61
62 #endif   /* _PG_NUMERIC_H_ */