PostgreSQL Source Code  git master
pgtypes_numeric.h
Go to the documentation of this file.
1 #ifndef PGTYPES_NUMERIC
2 #define PGTYPES_NUMERIC
3 
4 #include <pgtypes.h>
5 
6 #define NUMERIC_POS 0x0000
7 #define NUMERIC_NEG 0x4000
8 #define NUMERIC_NAN 0xC000
9 #define NUMERIC_NULL 0xF000
10 #define NUMERIC_MAX_PRECISION 1000
11 #define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION
12 #define NUMERIC_MIN_DISPLAY_SCALE 0
13 #define NUMERIC_MIN_SIG_DIGITS 16
14 
15 #define DECSIZE 30
16 
17 typedef unsigned char NumericDigit;
18 typedef struct
19 {
20  int ndigits; /* number of digits in digits[] - can be 0! */
21  int weight; /* weight of first digit */
22  int rscale; /* result scale */
23  int dscale; /* display scale */
24  int sign; /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
25  NumericDigit *buf; /* start of alloc'd space for digits[] */
26  NumericDigit *digits; /* decimal digits */
27 } numeric;
28 
29 typedef struct
30 {
31  int ndigits; /* number of digits in digits[] - can be 0! */
32  int weight; /* weight of first digit */
33  int rscale; /* result scale */
34  int dscale; /* display scale */
35  int sign; /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
36  NumericDigit digits[DECSIZE]; /* decimal digits */
37 } decimal;
38 
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #endif
43 
46 void PGTYPESnumeric_free(numeric *var);
47 void PGTYPESdecimal_free(decimal *var);
48 numeric *PGTYPESnumeric_from_asc(char *str, char **endptr);
49 char *PGTYPESnumeric_to_asc(numeric *num, int dscale);
50 int PGTYPESnumeric_add(numeric *var1, numeric *var2, numeric *result);
51 int PGTYPESnumeric_sub(numeric *var1, numeric *var2, numeric *result);
52 int PGTYPESnumeric_mul(numeric *var1, numeric *var2, numeric *result);
53 int PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric *result);
54 int PGTYPESnumeric_cmp(numeric *var1, numeric *var2);
55 int PGTYPESnumeric_from_int(signed int int_val, numeric *var);
56 int PGTYPESnumeric_from_long(signed long int long_val, numeric *var);
57 int PGTYPESnumeric_copy(numeric *src, numeric *dst);
58 int PGTYPESnumeric_from_double(double d, numeric *dst);
59 int PGTYPESnumeric_to_double(numeric *nv, double *dp);
60 int PGTYPESnumeric_to_int(numeric *nv, int *ip);
61 int PGTYPESnumeric_to_long(numeric *nv, long *lp);
64 
65 #ifdef __cplusplus
66 }
67 #endif
68 
69 #endif /* PGTYPES_NUMERIC */
int16 NumericDigit
Definition: numeric.c:102
Datum numeric(PG_FUNCTION_ARGS)
Definition: numeric.c:1246
const char * str
int digits
Definition: informix.c:691
int PGTYPESnumeric_from_double(double d, numeric *dst)
Definition: numeric.c:1411
int PGTYPESnumeric_copy(numeric *src, numeric *dst)
Definition: numeric.c:1388
int PGTYPESnumeric_from_decimal(decimal *src, numeric *dst)
Definition: numeric.c:1570
int PGTYPESnumeric_to_decimal(numeric *src, decimal *dst)
Definition: numeric.c:1547
void PGTYPESdecimal_free(decimal *var)
Definition: numeric.c:392
int PGTYPESnumeric_mul(numeric *var1, numeric *var2, numeric *result)
Definition: numeric.c:896
int PGTYPESnumeric_to_long(numeric *nv, long *lp)
Definition: numeric.c:1518
int PGTYPESnumeric_to_double(numeric *nv, double *dp)
Definition: numeric.c:1483
int PGTYPESnumeric_from_long(signed long int long_val, numeric *var)
Definition: numeric.c:1318
int PGTYPESnumeric_to_int(numeric *nv, int *ip)
Definition: numeric.c:1494
char * PGTYPESnumeric_to_asc(numeric *num, int dscale)
Definition: numeric.c:343
numeric * PGTYPESnumeric_new(void)
Definition: numeric.c:42
int PGTYPESnumeric_from_int(signed int int_val, numeric *var)
Definition: numeric.c:1309
int PGTYPESnumeric_sub(numeric *var1, numeric *var2, numeric *result)
Definition: numeric.c:765
decimal * PGTYPESdecimal_new(void)
Definition: numeric.c:59
#define DECSIZE
numeric * PGTYPESnumeric_from_asc(char *str, char **endptr)
Definition: numeric.c:321
void PGTYPESnumeric_free(numeric *var)
Definition: numeric.c:385
int PGTYPESnumeric_cmp(numeric *var1, numeric *var2)
Definition: numeric.c:1281
int PGTYPESnumeric_div(numeric *var1, numeric *var2, numeric *result)
Definition: numeric.c:1053
int PGTYPESnumeric_add(numeric *var1, numeric *var2, numeric *result)
Definition: numeric.c:637
unsigned char NumericDigit
NumericDigit * digits
NumericDigit * buf