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

Commit145d9fa

Browse files
committed
Code and docs review for numeric-factorial patch.
1 parentea4b9f1 commit145d9fa

File tree

3 files changed

+41
-27
lines changed

3 files changed

+41
-27
lines changed

‎doc/src/sgml/ref/drop_operator.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/drop_operator.sgml,v 1.23 2003/11/29 19:51:38 pgsql Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/drop_operator.sgml,v 1.24 2003/12/02 00:26:59 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -108,9 +108,9 @@ DROP OPERATOR ~ (none, bit);
108108

109109
<para>
110110
Remove the right unary factorial operator <literal>x!</literal>
111-
for type <type>integer</type>:
111+
for type <type>bigint</type>:
112112
<programlisting>
113-
DROP OPERATOR ! (integer, none);
113+
DROP OPERATOR ! (bigint, none);
114114
</programlisting>
115115
</para>
116116
</refsect1>

‎doc/src/sgml/typeconv.sgml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/typeconv.sgml,v 1.40 2003/12/01 21:53:15 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/typeconv.sgml,v 1.41 2003/12/02 00:26:59 tgl Exp $
33
-->
44

55
<chapter Id="typeconv">
@@ -412,7 +412,7 @@ type to resolve the unknown literals to.
412412
</example>
413413

414414
<example>
415-
<title>Absolute-Value andFactorial Operator Type Resolution</title>
415+
<title>Absolute-Value andNegation Operator Type Resolution</title>
416416

417417
<para>
418418
The <productname>PostgreSQL</productname> operator catalog has several
@@ -437,6 +437,30 @@ SELECT @ '-4.5e500' AS "abs";
437437
ERROR: "-4.5e500" is out of range for type double precision
438438
</screen>
439439
</para>
440+
441+
<para>
442+
On the other hand, the prefix operator <literal>~</> (bitwise negation)
443+
is defined only for integer data types, not for <type>float8</type>. So, if we
444+
try a similar case with <literal>~</>, we get:
445+
<screen>
446+
SELECT ~ '20' AS "negation";
447+
448+
ERROR: operator is not unique: ~ "unknown"
449+
HINT: Could not choose a best candidate operator. You may need to add explicit
450+
type casts.
451+
</screen>
452+
This happens because the system can't decide which of the several
453+
possible <literal>~</> operators should be preferred. We can help
454+
it out with an explicit cast:
455+
<screen>
456+
SELECT ~ CAST('20' AS int8) AS "negation";
457+
458+
negation
459+
----------
460+
-21
461+
(1 row)
462+
</screen>
463+
</para>
440464
</example>
441465

442466
</sect1>

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

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 1998-2003, PostgreSQL Global Development Group
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.69 2003/12/01 21:52:37 momjian Exp $
17+
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.70 2003/12/02 00:26:59 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -1290,49 +1290,39 @@ numeric_larger(PG_FUNCTION_ARGS)
12901290

12911291
/*
12921292
* numeric_fac()
1293-
* Computer factorial
1293+
*
1294+
* Compute factorial
12941295
*/
1295-
12961296
Datum
12971297
numeric_fac(PG_FUNCTION_ARGS)
12981298
{
1299-
13001299
int64num=PG_GETARG_INT64(0);
1301-
NumericVarcount;
1300+
Numericres;
13021301
NumericVarfact;
1303-
NumericVarzerovar;
13041302
NumericVarresult;
1305-
Numericres;
13061303

1307-
if(num<1) {
1304+
if (num <=1)
1305+
{
13081306
res=make_result(&const_one);
13091307
PG_RETURN_NUMERIC(res);
13101308
}
13111309

1312-
13131310
init_var(&fact);
1314-
init_var(&count);
13151311
init_var(&result);
1316-
init_var(&zerovar);
1317-
zero_var(&zerovar);
1318-
1319-
int8_to_numericvar((int64)num,&result);
1320-
set_var_from_var(&const_one,&count);
13211312

1322-
for(num=num-1;num>0;num--) {
1323-
set_var_from_var(&result,&count);
1313+
int8_to_numericvar(num,&result);
13241314

1325-
int8_to_numericvar((int64)num,&fact);
1315+
for (num=num-1;num>1;num--)
1316+
{
1317+
int8_to_numericvar(num,&fact);
13261318

1327-
mul_var(&count,&fact,&result,count.dscale+fact.dscale);
1319+
mul_var(&result,&fact,&result,0);
13281320
}
13291321

1330-
res=make_result(&count);
1322+
res=make_result(&result);
13311323

1332-
free_var(&count);
13331324
free_var(&fact);
13341325
free_var(&result);
1335-
free_var(&zerovar);
13361326

13371327
PG_RETURN_NUMERIC(res);
13381328
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp