aboutsummaryrefslogtreecommitdiff
path: root/src/include/utils/numeric.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-03-21 01:58:05 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-03-21 01:58:05 +0000
commitd72f6c75038d8d37e64a29a04b911f728044d83b (patch)
treeeceda56ef435a8b8317d0e123cbdb0fe2cd844e4 /src/include/utils/numeric.h
parent5ae424529b1bb9bf36eddbec57c7ba887698371e (diff)
downloadpostgresql-d72f6c75038d8d37e64a29a04b911f728044d83b.tar.gz
postgresql-d72f6c75038d8d37e64a29a04b911f728044d83b.zip
Reimplement NUMERIC datatype using base-10000 arithmetic; also improve
some of the algorithms for higher functions. I see about a factor of ten speedup on the 'numeric' regression test, but it's unlikely that that test is representative of real-world applications. initdb forced due to change of on-disk representation for NUMERIC.
Diffstat (limited to 'src/include/utils/numeric.h')
-rw-r--r--src/include/utils/numeric.h38
1 files changed, 16 insertions, 22 deletions
diff --git a/src/include/utils/numeric.h b/src/include/utils/numeric.h
index a8148d59cea..756d7c11232 100644
--- a/src/include/utils/numeric.h
+++ b/src/include/utils/numeric.h
@@ -1,15 +1,16 @@
-/* ----------
+/*-------------------------------------------------------------------------
+ *
* numeric.h
+ * Definitions for the exact numeric data type of Postgres
*
- * Definitions for the exact numeric data type of Postgres
+ * Original coding 1998, Jan Wieck. Heavily revised 2003, Tom Lane.
*
- * 1998 Jan Wieck
+ * Copyright (c) 1998-2003, PostgreSQL Global Development Group
*
- * $Id: numeric.h,v 1.16 2002/10/02 19:21:26 tgl Exp $
+ * $Id: numeric.h,v 1.17 2003/03/21 01:58:05 tgl Exp $
*
- * ----------
+ *-------------------------------------------------------------------------
*/
-
#ifndef _PG_NUMERIC_H_
#define _PG_NUMERIC_H_
@@ -34,12 +35,6 @@
*/
#define NUMERIC_MIN_SIG_DIGITS 16
-/*
- * Standard number of extra digits carried internally while doing
- * inexact calculations.
- */
-#define NUMERIC_EXTRA_DIGITS 4
-
/*
* Sign values and macros to deal with packing/unpacking n_sign_dscale
@@ -51,30 +46,29 @@
#define NUMERIC_DSCALE_MASK 0x3FFF
#define NUMERIC_SIGN(n) ((n)->n_sign_dscale & NUMERIC_SIGN_MASK)
#define NUMERIC_DSCALE(n) ((n)->n_sign_dscale & NUMERIC_DSCALE_MASK)
-#define NUMERIC_IS_NAN(n) (NUMERIC_SIGN(n) != NUMERIC_POS && \
- NUMERIC_SIGN(n) != NUMERIC_NEG)
+#define NUMERIC_IS_NAN(n) (NUMERIC_SIGN(n) != NUMERIC_POS && \
+ NUMERIC_SIGN(n) != NUMERIC_NEG)
/*
* The Numeric data type stored in the database
*
* NOTE: by convention, values in the packed form have been stripped of
- * all leading and trailing zeroes (except there will be a trailing zero
- * in the last byte, if the number of digits is odd). In particular,
- * if the value is zero, there will be no digits at all! The weight is
- * arbitrary in that case, but we normally set it to zero.
+ * all leading and trailing zero digits (where a "digit" is of base NBASE).
+ * In particular, if the value is zero, there will be no digits at all!
+ * The weight is arbitrary in that case, but we normally set it to zero.
*/
typedef struct NumericData
{
- int32 varlen; /* Variable size */
+ int32 varlen; /* Variable size (std varlena header) */
int16 n_weight; /* Weight of 1st digit */
- uint16 n_rscale; /* Result scale */
uint16 n_sign_dscale; /* Sign + display scale */
- unsigned char n_data[1]; /* Digit data (2 decimal digits/byte) */
+ char n_data[1]; /* Digits (really array of NumericDigit) */
} NumericData;
+
typedef NumericData *Numeric;
-#define NUMERIC_HDRSZ (sizeof(int32) + sizeof(uint16) * 3)
+#define NUMERIC_HDRSZ (sizeof(int32) + sizeof(int16) + sizeof(uint16))
/*