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 
48 numeric *PGTYPESnumeric_from_asc(char *, char **);
49 char *PGTYPESnumeric_to_asc(numeric *, int);
55 int PGTYPESnumeric_from_int(signed int, numeric *);
56 int PGTYPESnumeric_from_long(signed long int, numeric *);
58 int PGTYPESnumeric_from_double(double, numeric *);
59 int PGTYPESnumeric_to_double(numeric *, double *);
60 int PGTYPESnumeric_to_int(numeric *, int *);
61 int PGTYPESnumeric_to_long(numeric *, long *);
64 
65 #ifdef __cplusplus
66 }
67 #endif
68 
69 #endif /* PGTYPES_NUMERIC */
int PGTYPESnumeric_from_long(signed long int, numeric *)
Definition: numeric.c:1406
int PGTYPESnumeric_copy(numeric *, numeric *)
Definition: numeric.c:1476
int PGTYPESnumeric_from_decimal(decimal *, numeric *)
Definition: numeric.c:1653
unsigned char NumericDigit
decimal * PGTYPESdecimal_new(void)
Definition: numeric.c:145
int PGTYPESnumeric_to_decimal(numeric *, decimal *)
Definition: numeric.c:1630
NumericDigit * buf
int PGTYPESnumeric_from_double(double, numeric *)
Definition: numeric.c:1499
void PGTYPESnumeric_free(numeric *)
Definition: numeric.c:471
numeric * PGTYPESnumeric_new(void)
Definition: numeric.c:128
int PGTYPESnumeric_to_long(numeric *, long *)
Definition: numeric.c:1601
int PGTYPESnumeric_to_int(numeric *, int *)
Definition: numeric.c:1582
int PGTYPESnumeric_cmp(numeric *, numeric *)
Definition: numeric.c:1368
NumericDigit * digits
int PGTYPESnumeric_div(numeric *, numeric *, numeric *)
Definition: numeric.c:1139
Datum numeric(PG_FUNCTION_ARGS)
Definition: numeric.c:955
int16 NumericDigit
Definition: numeric.c:102
int PGTYPESnumeric_from_int(signed int, numeric *)
Definition: numeric.c:1397
char * PGTYPESnumeric_to_asc(numeric *, int)
Definition: numeric.c:429
numeric * PGTYPESnumeric_from_asc(char *, char **)
Definition: numeric.c:407
int PGTYPESnumeric_to_double(numeric *, double *)
Definition: numeric.c:1571
#define DECSIZE
void PGTYPESdecimal_free(decimal *)
Definition: numeric.c:478
int PGTYPESnumeric_add(numeric *, numeric *, numeric *)
Definition: numeric.c:723
int PGTYPESnumeric_mul(numeric *, numeric *, numeric *)
Definition: numeric.c:982
int PGTYPESnumeric_sub(numeric *, numeric *, numeric *)
Definition: numeric.c:851
int digits
Definition: informix.c:686