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
17typedef unsigned char NumericDigit;
18typedef 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
29typedef 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
40extern "C"
41{
42#endif
43
44numeric *PGTYPESnumeric_new(void);
45decimal *PGTYPESdecimal_new(void);
46void PGTYPESnumeric_free(numeric *);
47void PGTYPESdecimal_free(decimal *);
48numeric *PGTYPESnumeric_from_asc(char *, char **);
49char *PGTYPESnumeric_to_asc(numeric *, int);
50int PGTYPESnumeric_add(numeric *, numeric *, numeric *);
51int PGTYPESnumeric_sub(numeric *, numeric *, numeric *);
52int PGTYPESnumeric_mul(numeric *, numeric *, numeric *);
53int PGTYPESnumeric_div(numeric *, numeric *, numeric *);
54int PGTYPESnumeric_cmp(numeric *, numeric *);
55int PGTYPESnumeric_from_int(signed int, numeric *);
56int PGTYPESnumeric_from_long(signed long int, numeric *);
57int PGTYPESnumeric_copy(numeric *, numeric *);
58int PGTYPESnumeric_from_double(double, numeric *);
59int PGTYPESnumeric_to_double(numeric *, double *);
60int PGTYPESnumeric_to_int(numeric *, int *);
61int PGTYPESnumeric_to_long(numeric *, long *);
62int PGTYPESnumeric_to_decimal(numeric *, decimal *);
63int PGTYPESnumeric_from_decimal(decimal *, numeric *);
64
65#ifdef __cplusplus
66}
67#endif
68
69#endif /* PGTYPES_NUMERIC */
70