Header And Logo

PostgreSQL
| The world's most advanced open source database.

pgtypes_numeric.h

Go to the documentation of this file.
00001 #ifndef PGTYPES_NUMERIC
00002 #define PGTYPES_NUMERIC
00003 
00004 #define NUMERIC_POS                     0x0000
00005 #define NUMERIC_NEG                     0x4000
00006 #define NUMERIC_NAN                     0xC000
00007 #define NUMERIC_NULL                        0xF000
00008 #define NUMERIC_MAX_PRECISION           1000
00009 #define NUMERIC_MAX_DISPLAY_SCALE       NUMERIC_MAX_PRECISION
00010 #define NUMERIC_MIN_DISPLAY_SCALE       0
00011 #define NUMERIC_MIN_SIG_DIGITS          16
00012 
00013 #define DECSIZE 30
00014 
00015 typedef unsigned char NumericDigit;
00016 typedef struct
00017 {
00018     int         ndigits;        /* number of digits in digits[] - can be 0! */
00019     int         weight;         /* weight of first digit */
00020     int         rscale;         /* result scale */
00021     int         dscale;         /* display scale */
00022     int         sign;           /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
00023     NumericDigit *buf;          /* start of alloc'd space for digits[] */
00024     NumericDigit *digits;       /* decimal digits */
00025 } numeric;
00026 
00027 typedef struct
00028 {
00029     int         ndigits;        /* number of digits in digits[] - can be 0! */
00030     int         weight;         /* weight of first digit */
00031     int         rscale;         /* result scale */
00032     int         dscale;         /* display scale */
00033     int         sign;           /* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
00034     NumericDigit digits[DECSIZE];       /* decimal digits */
00035 } decimal;
00036 
00037 #ifdef __cplusplus
00038 extern      "C"
00039 {
00040 #endif
00041 
00042 numeric    *PGTYPESnumeric_new(void);
00043 decimal    *PGTYPESdecimal_new(void);
00044 void        PGTYPESnumeric_free(numeric *);
00045 void        PGTYPESdecimal_free(decimal *);
00046 numeric    *PGTYPESnumeric_from_asc(char *, char **);
00047 char       *PGTYPESnumeric_to_asc(numeric *, int);
00048 int         PGTYPESnumeric_add(numeric *, numeric *, numeric *);
00049 int         PGTYPESnumeric_sub(numeric *, numeric *, numeric *);
00050 int         PGTYPESnumeric_mul(numeric *, numeric *, numeric *);
00051 int         PGTYPESnumeric_div(numeric *, numeric *, numeric *);
00052 int         PGTYPESnumeric_cmp(numeric *, numeric *);
00053 int         PGTYPESnumeric_from_int(signed int, numeric *);
00054 int         PGTYPESnumeric_from_long(signed long int, numeric *);
00055 int         PGTYPESnumeric_copy(numeric *, numeric *);
00056 int         PGTYPESnumeric_from_double(double, numeric *);
00057 int         PGTYPESnumeric_to_double(numeric *, double *);
00058 int         PGTYPESnumeric_to_int(numeric *, int *);
00059 int         PGTYPESnumeric_to_long(numeric *, long *);
00060 int         PGTYPESnumeric_to_decimal(numeric *, decimal *);
00061 int         PGTYPESnumeric_from_decimal(decimal *, numeric *);
00062 
00063 #ifdef __cplusplus
00064 }
00065 #endif
00066 
00067 #endif   /* PGTYPES_NUMERIC */