Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8a4dc94

Browse files
committed
Make details of the Numeric representation private to numeric.c.
Review by Tom Lane.
1 parentf223bb7 commit8a4dc94

File tree

4 files changed

+75
-50
lines changed

4 files changed

+75
-50
lines changed

‎contrib/btree_gist/btree_numeric.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/btree_gist/btree_numeric.c,v 1.13 2009/06/11 14:48:50 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/btree_gist/btree_numeric.c,v 1.14 2010/07/30 04:30:23 rhaas Exp $
33
*/
44
#include"btree_gist.h"
55

@@ -185,9 +185,9 @@ gbt_numeric_penalty(PG_FUNCTION_ARGS)
185185
NumericGetDatum(os)
186186
));
187187

188-
if (NUMERIC_IS_NAN(us))
188+
if (numeric_is_nan(us))
189189
{
190-
if (NUMERIC_IS_NAN(os))
190+
if (numeric_is_nan(os))
191191
*result=0.0;
192192
else
193193
*result=1.0;

‎src/backend/utils/adt/format_type.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/format_type.c,v 1.53 2010/02/14 18:42:16 rhaas Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/format_type.c,v 1.54 2010/07/30 04:30:23 rhaas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -387,15 +387,7 @@ type_maximum_size(Oid type_oid, int32 typemod)
387387
+VARHDRSZ;
388388

389389
caseNUMERICOID:
390-
/* precision (ie, max # of digits) is in upper bits of typmod */
391-
if (typemod>VARHDRSZ)
392-
{
393-
intprecision= ((typemod-VARHDRSZ) >>16)&0xffff;
394-
395-
/* Numeric stores 2 decimal digits/byte, plus header */
396-
return (precision+1) /2+NUMERIC_HDRSZ;
397-
}
398-
break;
390+
returnnumeric_maximum_size(typemod);
399391

400392
caseVARBITOID:
401393
caseBITOID:

‎src/backend/utils/adt/numeric.c

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 1998-2010, PostgreSQL Global Development Group
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.123 2010/02/26 02:01:09 momjian Exp $
17+
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.124 2010/07/30 04:30:23 rhaas Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -35,6 +35,38 @@
3535
#include"utils/int8.h"
3636
#include"utils/numeric.h"
3737

38+
/*
39+
* Sign values and macros to deal with packing/unpacking n_sign_dscale
40+
*/
41+
#defineNUMERIC_SIGN_MASK0xC000
42+
#defineNUMERIC_POS0x0000
43+
#defineNUMERIC_NEG0x4000
44+
#defineNUMERIC_NAN0xC000
45+
#defineNUMERIC_DSCALE_MASK 0x3FFF
46+
#defineNUMERIC_SIGN(n)((n)->n_sign_dscale & NUMERIC_SIGN_MASK)
47+
#defineNUMERIC_DSCALE(n)((n)->n_sign_dscale & NUMERIC_DSCALE_MASK)
48+
#defineNUMERIC_IS_NAN(n)(NUMERIC_SIGN(n) != NUMERIC_POS &&\
49+
NUMERIC_SIGN(n) != NUMERIC_NEG)
50+
#defineNUMERIC_HDRSZ(VARHDRSZ + sizeof(uint16) + sizeof(int16))
51+
52+
53+
/*
54+
* The Numeric data type stored in the database
55+
*
56+
* NOTE: by convention, values in the packed form have been stripped of
57+
* all leading and trailing zero digits (where a "digit" is of base NBASE).
58+
* In particular, if the value is zero, there will be no digits at all!
59+
* The weight is arbitrary in that case, but we normally set it to zero.
60+
*/
61+
structNumericData
62+
{
63+
int32vl_len_;/* varlena header (do not touch directly!) */
64+
uint16n_sign_dscale;/* Sign + display scale */
65+
int16n_weight;/* Weight of 1st digit*/
66+
charn_data[1];/* Digits (really array of NumericDigit) */
67+
};
68+
69+
3870
/* ----------
3971
* Uncomment the following to enable compilation of dump_numeric()
4072
* and dump_var() and to get a dump of any result produced by make_result().
@@ -427,6 +459,37 @@ numeric_out(PG_FUNCTION_ARGS)
427459
PG_RETURN_CSTRING(str);
428460
}
429461

462+
/*
463+
* numeric_is_nan() -
464+
*
465+
* Is Numeric value a NaN?
466+
*/
467+
bool
468+
numeric_is_nan(Numericnum)
469+
{
470+
returnNUMERIC_IS_NAN(num);
471+
}
472+
473+
/*
474+
* numeric_maximum_size() -
475+
*
476+
* Maximum size of a numeric with given typmod, or -1 if unlimited/unknown.
477+
*/
478+
int32
479+
numeric_maximum_size(int32typemod)
480+
{
481+
intprecision;
482+
483+
if (typemod <=VARHDRSZ)
484+
return-1;
485+
486+
/* precision (ie, max # of digits) is in upper bits of typmod */
487+
precision= ((typemod-VARHDRSZ) >>16)&0xffff;
488+
489+
/* Numeric stores 2 decimal digits/byte, plus header */
490+
return (precision+1) /2+NUMERIC_HDRSZ;
491+
}
492+
430493
/*
431494
* numeric_out_sci() -
432495
*

‎src/include/utils/numeric.h

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1998-2010, PostgreSQL Global Development Group
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/numeric.h,v 1.29 2010/01/02 16:58:10 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/numeric.h,v 1.30 2010/07/30 04:30:23 rhaas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -37,41 +37,9 @@
3737
*/
3838
#defineNUMERIC_MIN_SIG_DIGITS16
3939

40-
41-
/*
42-
* Sign values and macros to deal with packing/unpacking n_sign_dscale
43-
*/
44-
#defineNUMERIC_SIGN_MASK0xC000
45-
#defineNUMERIC_POS0x0000
46-
#defineNUMERIC_NEG0x4000
47-
#defineNUMERIC_NAN0xC000
48-
#defineNUMERIC_DSCALE_MASK 0x3FFF
49-
#defineNUMERIC_SIGN(n)((n)->n_sign_dscale & NUMERIC_SIGN_MASK)
50-
#defineNUMERIC_DSCALE(n)((n)->n_sign_dscale & NUMERIC_DSCALE_MASK)
51-
#defineNUMERIC_IS_NAN(n)(NUMERIC_SIGN(n) != NUMERIC_POS &&\
52-
NUMERIC_SIGN(n) != NUMERIC_NEG)
53-
54-
55-
/*
56-
* The Numeric data type stored in the database
57-
*
58-
* NOTE: by convention, values in the packed form have been stripped of
59-
* all leading and trailing zero digits (where a "digit" is of base NBASE).
60-
* In particular, if the value is zero, there will be no digits at all!
61-
* The weight is arbitrary in that case, but we normally set it to zero.
62-
*/
63-
typedefstructNumericData
64-
{
65-
int32vl_len_;/* varlena header (do not touch directly!) */
66-
uint16n_sign_dscale;/* Sign + display scale */
67-
int16n_weight;/* Weight of 1st digit*/
68-
charn_data[1];/* Digits (really array of NumericDigit) */
69-
}NumericData;
70-
71-
typedefNumericData*Numeric;
72-
73-
#defineNUMERIC_HDRSZ(VARHDRSZ + sizeof(uint16) + sizeof(int16))
74-
40+
/* The actual contents of Numeric are private to numeric.c */
41+
structNumericData;
42+
typedefstructNumericData*Numeric;
7543

7644
/*
7745
* fmgr interface macros
@@ -87,6 +55,8 @@ typedef NumericData *Numeric;
8755
/*
8856
* Utility functions in numeric.c
8957
*/
58+
externboolnumeric_is_nan(Numericnum);
59+
int32numeric_maximum_size(int32typemod);
9060
externchar*numeric_out_sci(Numericnum,intscale);
9161

9262
#endif/* _PG_NUMERIC_H_ */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp