]> granicus.if.org Git - postgresql/blob - src/include/utils/numeric.h
Change my-function-name-- to my_function_name, and optimizer renames.
[postgresql] / src / include / utils / numeric.h
1 /* ----------
2  * numeric.h
3  *
4  *      Definitions for the exact numeric data type of Postgres
5  *
6  *      1998 Jan Wieck
7  *
8  * $Header: /cvsroot/pgsql/src/include/utils/numeric.h,v 1.4 1999/02/13 23:22:26 momjian Exp $
9  *
10  * ----------
11  */
12
13 #ifndef _PG_NUMERIC_H_
14 #define _PG_NUMERIC_H_
15
16 #include "postgres.h"
17
18
19 /* ----------
20  * The hardcoded limits and defaults of the numeric data type
21  * ----------
22  */
23 #define NUMERIC_MAX_PRECISION           1000
24 #define NUMERIC_DEFAULT_PRECISION       30
25 #define NUMERIC_DEFAULT_SCALE           6
26
27 #define NUMERIC_MAX_DISPLAY_SCALE       NUMERIC_MAX_PRECISION
28 #define NUMERIC_MIN_DISPLAY_SCALE       NUMERIC_DEFAULT_SCALE + 4
29
30 #define NUMERIC_MAX_RESULT_SCALE        (NUMERIC_MAX_PRECISION * 2)
31 #define NUMERIC_MIN_RESULT_SCALE        (NUMERIC_DEFAULT_PRECISION + 4)
32
33 #define NUMERIC_UNPACKED_DATASIZE       (NUMERIC_MAX_PRECISION * 2 + 4)
34
35
36 /* ----------
37  * Sign values and macros to deal with n_sign_dscale
38  * ----------
39  */
40 #define NUMERIC_SIGN_MASK       0xC000
41 #define NUMERIC_POS                     0x0000
42 #define NUMERIC_NEG                     0x4000
43 #define NUMERIC_NAN                     0xC000
44 #define NUMERIC_SIGN(n)         ((n)->n_sign_dscale & NUMERIC_SIGN_MASK)
45 #define NUMERIC_DSCALE(n)       ((n)->n_sign_dscale & ~NUMERIC_SIGN_MASK)
46 #define NUMERIC_IS_NAN(n)       (NUMERIC_SIGN(n) != NUMERIC_POS &&                      \
47                                                                 NUMERIC_SIGN(n) != NUMERIC_NEG)
48
49
50 /* ----------
51  * The Numeric data type stored in the database
52  * ----------
53  */
54 typedef struct NumericData {
55         int32                   varlen;                 /* Variable size                */
56         int16                   n_weight;               /* Weight of 1st digit  */
57         uint16                  n_rscale;               /* Result scale                 */
58         uint16                  n_sign_dscale;  /* Sign + display scale */
59         unsigned char   n_data[1];              /* Digit data                   */
60 } NumericData;
61 typedef NumericData *Numeric;
62
63 #define NUMERIC_HDRSZ   (sizeof(int32) + sizeof(uint16) * 3)
64
65
66 #endif /* _PG_NUMERIC_H_ */
67