2003-03-20 20:58:05 -05:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
1999-02-13 18:22:53 -05:00
|
|
|
* numeric.h
|
2003-03-20 20:58:05 -05:00
|
|
|
* Definitions for the exact numeric data type of Postgres
|
1998-12-30 14:56:35 -05:00
|
|
|
*
|
2003-03-20 20:58:05 -05:00
|
|
|
* Original coding 1998, Jan Wieck. Heavily revised 2003, Tom Lane.
|
1998-12-30 14:56:35 -05:00
|
|
|
*
|
2012-01-01 18:01:58 -05:00
|
|
|
* Copyright (c) 1998-2012, PostgreSQL Global Development Group
|
1998-12-30 14:56:35 -05:00
|
|
|
*
|
2010-09-20 16:08:53 -04:00
|
|
|
* src/include/utils/numeric.h
|
1998-12-30 14:56:35 -05:00
|
|
|
*
|
2003-03-20 20:58:05 -05:00
|
|
|
*-------------------------------------------------------------------------
|
1998-12-30 14:56:35 -05:00
|
|
|
*/
|
|
|
|
|
#ifndef _PG_NUMERIC_H_
|
|
|
|
|
#define _PG_NUMERIC_H_
|
|
|
|
|
|
2006-07-11 09:54:25 -04:00
|
|
|
#include "fmgr.h"
|
|
|
|
|
|
2002-10-02 15:21:26 -04:00
|
|
|
/*
|
|
|
|
|
* Hardcoded precision limit - arbitrary, but must be small enough that
|
|
|
|
|
* dscale values will fit in 14 bits.
|
1998-12-30 14:56:35 -05:00
|
|
|
*/
|
1999-01-05 06:12:11 -05:00
|
|
|
#define NUMERIC_MAX_PRECISION 1000
|
1998-12-30 14:56:35 -05:00
|
|
|
|
2002-10-02 15:21:26 -04:00
|
|
|
/*
|
2000-01-15 18:42:49 -05:00
|
|
|
* Internal limits on the scales chosen for calculation results
|
|
|
|
|
*/
|
1999-05-25 12:15:34 -04:00
|
|
|
#define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION
|
2002-10-02 15:21:26 -04:00
|
|
|
#define NUMERIC_MIN_DISPLAY_SCALE 0
|
1998-12-30 14:56:35 -05:00
|
|
|
|
1999-05-25 12:15:34 -04:00
|
|
|
#define NUMERIC_MAX_RESULT_SCALE (NUMERIC_MAX_PRECISION * 2)
|
1998-12-30 14:56:35 -05:00
|
|
|
|
2002-10-02 15:21:26 -04:00
|
|
|
/*
|
|
|
|
|
* For inherently inexact calculations such as division and square root,
|
|
|
|
|
* we try to get at least this many significant digits; the idea is to
|
|
|
|
|
* deliver a result no worse than float8 would.
|
|
|
|
|
*/
|
|
|
|
|
#define NUMERIC_MIN_SIG_DIGITS 16
|
1998-12-30 14:56:35 -05:00
|
|
|
|
2010-07-30 00:30:23 -04:00
|
|
|
/* The actual contents of Numeric are private to numeric.c */
|
|
|
|
|
struct NumericData;
|
|
|
|
|
typedef struct NumericData *Numeric;
|
1998-12-30 14:56:35 -05:00
|
|
|
|
2000-06-13 03:35:40 -04:00
|
|
|
/*
|
|
|
|
|
* fmgr interface macros
|
|
|
|
|
*/
|
|
|
|
|
|
2001-03-21 23:01:46 -05:00
|
|
|
#define DatumGetNumeric(X) ((Numeric) PG_DETOAST_DATUM(X))
|
|
|
|
|
#define DatumGetNumericCopy(X) ((Numeric) PG_DETOAST_DATUM_COPY(X))
|
|
|
|
|
#define NumericGetDatum(X) PointerGetDatum(X)
|
|
|
|
|
#define PG_GETARG_NUMERIC(n) DatumGetNumeric(PG_GETARG_DATUM(n))
|
2000-07-16 23:05:41 -04:00
|
|
|
#define PG_GETARG_NUMERIC_COPY(n) DatumGetNumericCopy(PG_GETARG_DATUM(n))
|
2001-03-21 23:01:46 -05:00
|
|
|
#define PG_RETURN_NUMERIC(x) return NumericGetDatum(x)
|
2001-10-28 01:26:15 -05:00
|
|
|
|
2009-08-10 14:29:27 -04:00
|
|
|
/*
|
|
|
|
|
* Utility functions in numeric.c
|
|
|
|
|
*/
|
2010-07-30 00:30:23 -04:00
|
|
|
extern bool numeric_is_nan(Numeric num);
|
2011-04-10 11:42:00 -04:00
|
|
|
int32 numeric_maximum_size(int32 typmod);
|
2009-08-10 14:29:27 -04:00
|
|
|
extern char *numeric_out_sci(Numeric num, int scale);
|
|
|
|
|
|
2001-11-05 12:46:40 -05:00
|
|
|
#endif /* _PG_NUMERIC_H_ */
|