Eneboo - Documentación para desarrolladores
src/libpq/include/utils/numeric.h
Ir a la documentación de este archivo.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * numeric.h
00004  *        Definitions for the exact numeric data type of Postgres
00005  *
00006  * Original coding 1998, Jan Wieck.  Heavily revised 2003, Tom Lane.
00007  *
00008  * Copyright (c) 1998-2005, PostgreSQL Global Development Group
00009  *
00010  * $PostgreSQL: pgsql/src/include/utils/numeric.h,v 1.20 2005/01/01 05:43:09 momjian Exp $
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef _PG_NUMERIC_H_
00015 #define _PG_NUMERIC_H_
00016 
00017 /*
00018  * Hardcoded precision limit - arbitrary, but must be small enough that
00019  * dscale values will fit in 14 bits.
00020  */
00021 #define NUMERIC_MAX_PRECISION           1000
00022 
00023 /*
00024  * Internal limits on the scales chosen for calculation results
00025  */
00026 #define NUMERIC_MAX_DISPLAY_SCALE       NUMERIC_MAX_PRECISION
00027 #define NUMERIC_MIN_DISPLAY_SCALE       0
00028 
00029 #define NUMERIC_MAX_RESULT_SCALE        (NUMERIC_MAX_PRECISION * 2)
00030 
00031 /*
00032  * For inherently inexact calculations such as division and square root,
00033  * we try to get at least this many significant digits; the idea is to
00034  * deliver a result no worse than float8 would.
00035  */
00036 #define NUMERIC_MIN_SIG_DIGITS          16
00037 
00038 
00039 /*
00040  * Sign values and macros to deal with packing/unpacking n_sign_dscale
00041  */
00042 #define NUMERIC_SIGN_MASK       0xC000
00043 #define NUMERIC_POS                     0x0000
00044 #define NUMERIC_NEG                     0x4000
00045 #define NUMERIC_NAN                     0xC000
00046 #define NUMERIC_DSCALE_MASK 0x3FFF
00047 #define NUMERIC_SIGN(n)         ((n)->n_sign_dscale & NUMERIC_SIGN_MASK)
00048 #define NUMERIC_DSCALE(n)       ((n)->n_sign_dscale & NUMERIC_DSCALE_MASK)
00049 #define NUMERIC_IS_NAN(n)       (NUMERIC_SIGN(n) != NUMERIC_POS &&      \
00050                                                          NUMERIC_SIGN(n) != NUMERIC_NEG)
00051 
00052 
00053 /*
00054  * The Numeric data type stored in the database
00055  *
00056  * NOTE: by convention, values in the packed form have been stripped of
00057  * all leading and trailing zero digits (where a "digit" is of base NBASE).
00058  * In particular, if the value is zero, there will be no digits at all!
00059  * The weight is arbitrary in that case, but we normally set it to zero.
00060  */
00061 typedef struct NumericData
00062 {
00063         int32           varlen;                 /* Variable size (std varlena header) */
00064         int16           n_weight;               /* Weight of 1st digit  */
00065         uint16          n_sign_dscale;  /* Sign + display scale */
00066         char            n_data[1];              /* Digits (really array of NumericDigit) */
00067 } NumericData;
00068 
00069 typedef NumericData *Numeric;
00070 
00071 #define NUMERIC_HDRSZ   (sizeof(int32) + sizeof(int16) + sizeof(uint16))
00072 
00073 
00074 /*
00075  * fmgr interface macros
00076  */
00077 
00078 #define DatumGetNumeric(X)                ((Numeric) PG_DETOAST_DATUM(X))
00079 #define DatumGetNumericCopy(X)    ((Numeric) PG_DETOAST_DATUM_COPY(X))
00080 #define NumericGetDatum(X)                PointerGetDatum(X)
00081 #define PG_GETARG_NUMERIC(n)      DatumGetNumeric(PG_GETARG_DATUM(n))
00082 #define PG_GETARG_NUMERIC_COPY(n) DatumGetNumericCopy(PG_GETARG_DATUM(n))
00083 #define PG_RETURN_NUMERIC(x)      return NumericGetDatum(x)
00084 
00085 #endif   /* _PG_NUMERIC_H_ */
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'