Header And Logo

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

numeric.h

Go to the documentation of this file.
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-2013, PostgreSQL Global Development Group
00009  *
00010  * src/include/utils/numeric.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef _PG_NUMERIC_H_
00015 #define _PG_NUMERIC_H_
00016 
00017 #include "fmgr.h"
00018 
00019 /*
00020  * Hardcoded precision limit - arbitrary, but must be small enough that
00021  * dscale values will fit in 14 bits.
00022  */
00023 #define NUMERIC_MAX_PRECISION       1000
00024 
00025 /*
00026  * Internal limits on the scales chosen for calculation results
00027  */
00028 #define NUMERIC_MAX_DISPLAY_SCALE   NUMERIC_MAX_PRECISION
00029 #define NUMERIC_MIN_DISPLAY_SCALE   0
00030 
00031 #define NUMERIC_MAX_RESULT_SCALE    (NUMERIC_MAX_PRECISION * 2)
00032 
00033 /*
00034  * For inherently inexact calculations such as division and square root,
00035  * we try to get at least this many significant digits; the idea is to
00036  * deliver a result no worse than float8 would.
00037  */
00038 #define NUMERIC_MIN_SIG_DIGITS      16
00039 
00040 /* The actual contents of Numeric are private to numeric.c */
00041 struct NumericData;
00042 typedef struct NumericData *Numeric;
00043 
00044 /*
00045  * fmgr interface macros
00046  */
00047 
00048 #define DatumGetNumeric(X)        ((Numeric) PG_DETOAST_DATUM(X))
00049 #define DatumGetNumericCopy(X)    ((Numeric) PG_DETOAST_DATUM_COPY(X))
00050 #define NumericGetDatum(X)        PointerGetDatum(X)
00051 #define PG_GETARG_NUMERIC(n)      DatumGetNumeric(PG_GETARG_DATUM(n))
00052 #define PG_GETARG_NUMERIC_COPY(n) DatumGetNumericCopy(PG_GETARG_DATUM(n))
00053 #define PG_RETURN_NUMERIC(x)      return NumericGetDatum(x)
00054 
00055 /*
00056  * Utility functions in numeric.c
00057  */
00058 extern bool numeric_is_nan(Numeric num);
00059 int32       numeric_maximum_size(int32 typmod);
00060 extern char *numeric_out_sci(Numeric num, int scale);
00061 
00062 #endif   /* _PG_NUMERIC_H_ */