PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
numeric.h
Go to the documentation of this file.
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 
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);
60 extern char *numeric_out_sci(Numeric num, int scale);
61 extern char *numeric_normalize(Numeric num);
62 
63 #endif /* _PG_NUMERIC_H_ */
char * numeric_out_sci(Numeric num, int scale)
Definition: numeric.c:667
int scale
Definition: pgbench.c:103
struct NumericData * Numeric
Definition: numeric.h:42
signed int int32
Definition: c.h:242
char * numeric_normalize(Numeric num)
Definition: numeric.c:694
int32 numeric_maximum_size(int32 typmod)
Definition: numeric.c:628
bool numeric_is_nan(Numeric num)
Definition: numeric.c:617