Debian Codegraph @

src/interfaces/ecpg/include/pgtypes_numeric.h

raw
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
44 numeric *PGTYPESnumeric_new(void);
45 decimal *PGTYPESdecimal_new(void);
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);
62 int PGTYPESnumeric_to_decimal(numeric *src, decimal *dst);
63 int PGTYPESnumeric_from_decimal(decimal *src, numeric *dst);
64
65 #ifdef __cplusplus
66 }
67 #endif
68
69 #endif /* PGTYPES_NUMERIC */