Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
numeric.h106 linesDownload Raw Back to utils
1/*-------------------------------------------------------------------------2 *3 * numeric.h4 *	  Definitions for the exact numeric data type of Postgres5 *6 * Original coding 1998, Jan Wieck.  Heavily revised 2003, Tom Lane.7 *8 * Copyright (c) 1998-2023, PostgreSQL Global Development Group9 *10 * src/include/utils/numeric.h11 *12 *-------------------------------------------------------------------------13 */14#ifndef _PG_NUMERIC_H_15#define _PG_NUMERIC_H_16 17#include "fmgr.h"18 19/*20 * Limits on the precision and scale specifiable in a NUMERIC typmod.  The21 * precision is strictly positive, but the scale may be positive or negative.22 * A negative scale implies rounding before the decimal point.23 *24 * Note that the minimum display scale defined below is zero --- we always25 * display all digits before the decimal point, even when the scale is26 * negative.27 *28 * Note that the implementation limits on the precision and display scale of a29 * numeric value are much larger --- beware of what you use these for!30 */31#define NUMERIC_MAX_PRECISION		100032 33#define NUMERIC_MIN_SCALE			(-1000)34#define NUMERIC_MAX_SCALE			100035 36/*37 * Internal limits on the scales chosen for calculation results38 */39#define NUMERIC_MAX_DISPLAY_SCALE	NUMERIC_MAX_PRECISION40#define NUMERIC_MIN_DISPLAY_SCALE	041 42#define NUMERIC_MAX_RESULT_SCALE	(NUMERIC_MAX_PRECISION * 2)43 44/*45 * For inherently inexact calculations such as division and square root,46 * we try to get at least this many significant digits; the idea is to47 * deliver a result no worse than float8 would.48 */49#define NUMERIC_MIN_SIG_DIGITS		1650 51/* The actual contents of Numeric are private to numeric.c */52struct NumericData;53typedef struct NumericData *Numeric;54 55/*56 * fmgr interface macros57 */58 59static inline Numeric60DatumGetNumeric(Datum X)61{62	return (Numeric) PG_DETOAST_DATUM(X);63}64 65static inline Numeric66DatumGetNumericCopy(Datum X)67{68	return (Numeric) PG_DETOAST_DATUM_COPY(X);69}70 71static inline Datum72NumericGetDatum(Numeric X)73{74	return PointerGetDatum(X);75}76 77#define PG_GETARG_NUMERIC(n)	  DatumGetNumeric(PG_GETARG_DATUM(n))78#define PG_GETARG_NUMERIC_COPY(n) DatumGetNumericCopy(PG_GETARG_DATUM(n))79#define PG_RETURN_NUMERIC(x)	  return NumericGetDatum(x)80 81/*82 * Utility functions in numeric.c83 */84extern bool numeric_is_nan(Numeric num);85extern bool numeric_is_inf(Numeric num);86extern int32 numeric_maximum_size(int32 typmod);87extern char *numeric_out_sci(Numeric num, int scale);88extern char *numeric_normalize(Numeric num);89 90extern Numeric int64_to_numeric(int64 val);91extern Numeric int64_div_fast_to_numeric(int64 val1, int log10val2);92 93extern Numeric numeric_add_opt_error(Numeric num1, Numeric num2,94									 bool *have_error);95extern Numeric numeric_sub_opt_error(Numeric num1, Numeric num2,96									 bool *have_error);97extern Numeric numeric_mul_opt_error(Numeric num1, Numeric num2,98									 bool *have_error);99extern Numeric numeric_div_opt_error(Numeric num1, Numeric num2,100									 bool *have_error);101extern Numeric numeric_mod_opt_error(Numeric num1, Numeric num2,102									 bool *have_error);103extern int32 numeric_int4_opt_error(Numeric num, bool *have_error);104 105#endif							/* _PG_NUMERIC_H_ */106 
codekingpro/portable-devtools · Team Ai