1/*-------------------------------------------------------------------------
4 * Definitions for the exact numeric data type of Postgres
6 * Original coding 1998, Jan Wieck. Heavily revised 2003, Tom Lane.
8 * Copyright (c) 1998-2025, PostgreSQL Global Development Group
10 * src/include/utils/numeric.h
12 *-------------------------------------------------------------------------
20/* forward declaration to avoid node.h include */
24 * Limits on the precision and scale specifiable in a NUMERIC typmod. The
25 * precision is strictly positive, but the scale may be positive or negative.
26 * A negative scale implies rounding before the decimal point.
28 * Note that the minimum display scale defined below is zero --- we always
29 * display all digits before the decimal point, even when the scale is
32 * Note that the implementation limits on the precision and display scale of a
33 * numeric value are much larger --- beware of what you use these for!
35 #define NUMERIC_MAX_PRECISION 1000
37 #define NUMERIC_MIN_SCALE (-1000)
38 #define NUMERIC_MAX_SCALE 1000
41 * Internal limits on the scales chosen for calculation results
43 #define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION
44 #define NUMERIC_MIN_DISPLAY_SCALE 0
46 #define NUMERIC_MAX_RESULT_SCALE (NUMERIC_MAX_PRECISION * 2)
49 * For inherently inexact calculations such as division and square root,
50 * we try to get at least this many significant digits; the idea is to
51 * deliver a result no worse than float8 would.
53 #define NUMERIC_MIN_SIG_DIGITS 16
55/* The actual contents of Numeric are private to numeric.c */
60 * fmgr interface macros
81 #define PG_GETARG_NUMERIC(n) DatumGetNumeric(PG_GETARG_DATUM(n))
82 #define PG_GETARG_NUMERIC_COPY(n) DatumGetNumericCopy(PG_GETARG_DATUM(n))
83 #define PG_RETURN_NUMERIC(x) return NumericGetDatum(x)
86 * Utility functions in numeric.c
108#endif /* _PG_NUMERIC_H_ */
#define PG_DETOAST_DATUM_COPY(datum)
#define PG_DETOAST_DATUM(datum)
char * numeric_normalize(Numeric num)
char * numeric_out_sci(Numeric num, int scale)
int32 numeric_maximum_size(int32 typmod)
static Numeric DatumGetNumericCopy(Datum X)
Numeric int64_to_numeric(int64 val)
Numeric random_numeric(pg_prng_state *state, Numeric rmin, Numeric rmax)
Numeric numeric_mod_safe(Numeric num1, Numeric num2, Node *escontext)
int32 numeric_int4_safe(Numeric num, Node *escontext)
static Numeric DatumGetNumeric(Datum X)
Numeric numeric_add_safe(Numeric num1, Numeric num2, Node *escontext)
Numeric int64_div_fast_to_numeric(int64 val1, int log10val2)
int64 numeric_int8_safe(Numeric num, Node *escontext)
Numeric numeric_div_safe(Numeric num1, Numeric num2, Node *escontext)
Numeric numeric_sub_safe(Numeric num1, Numeric num2, Node *escontext)
struct NumericData * Numeric
bool numeric_is_nan(Numeric num)
Numeric numeric_mul_safe(Numeric num1, Numeric num2, Node *escontext)
bool numeric_is_inf(Numeric num)
static Datum NumericGetDatum(Numeric X)
static Datum PointerGetDatum(const void *X)