4 * Definitions for the exact numeric data type of Postgres
8 * $Header: /cvsroot/pgsql/src/include/utils/numeric.h,v 1.4 1999/02/13 23:22:26 momjian Exp $
13 #ifndef _PG_NUMERIC_H_
14 #define _PG_NUMERIC_H_
20 * The hardcoded limits and defaults of the numeric data type
23 #define NUMERIC_MAX_PRECISION 1000
24 #define NUMERIC_DEFAULT_PRECISION 30
25 #define NUMERIC_DEFAULT_SCALE 6
27 #define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION
28 #define NUMERIC_MIN_DISPLAY_SCALE NUMERIC_DEFAULT_SCALE + 4
30 #define NUMERIC_MAX_RESULT_SCALE (NUMERIC_MAX_PRECISION * 2)
31 #define NUMERIC_MIN_RESULT_SCALE (NUMERIC_DEFAULT_PRECISION + 4)
33 #define NUMERIC_UNPACKED_DATASIZE (NUMERIC_MAX_PRECISION * 2 + 4)
37 * Sign values and macros to deal with n_sign_dscale
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)
51 * The Numeric data type stored in the database
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 */
61 typedef NumericData *Numeric;
63 #define NUMERIC_HDRSZ (sizeof(int32) + sizeof(uint16) * 3)
66 #endif /* _PG_NUMERIC_H_ */