Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
145d9fa4
Commit
145d9fa4
authored
Dec 02, 2003
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code and docs review for numeric-factorial patch.
parent
ea4b9f14
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
27 deletions
+41
-27
doc/src/sgml/ref/drop_operator.sgml
doc/src/sgml/ref/drop_operator.sgml
+3
-3
doc/src/sgml/typeconv.sgml
doc/src/sgml/typeconv.sgml
+26
-2
src/backend/utils/adt/numeric.c
src/backend/utils/adt/numeric.c
+12
-22
No files found.
doc/src/sgml/ref/drop_operator.sgml
View file @
145d9fa4
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/drop_operator.sgml,v 1.2
3 2003/11/29 19:51:38 pgsq
l Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/drop_operator.sgml,v 1.2
4 2003/12/02 00:26:59 tg
l Exp $
PostgreSQL documentation
-->
...
...
@@ -108,9 +108,9 @@ DROP OPERATOR ~ (none, bit);
<para>
Remove the right unary factorial operator <literal>x!</literal>
for type <type>
integer
</type>:
for type <type>
bigint
</type>:
<programlisting>
DROP OPERATOR ! (
integer
, none);
DROP OPERATOR ! (
bigint
, none);
</programlisting>
</para>
</refsect1>
...
...
doc/src/sgml/typeconv.sgml
View file @
145d9fa4
<!--
$PostgreSQL: pgsql/doc/src/sgml/typeconv.sgml,v 1.4
0 2003/12/01 21:53:15 momjian
Exp $
$PostgreSQL: pgsql/doc/src/sgml/typeconv.sgml,v 1.4
1 2003/12/02 00:26:59 tgl
Exp $
-->
<chapter Id="typeconv">
...
...
@@ -412,7 +412,7 @@ type to resolve the unknown literals to.
</example>
<example>
<title>Absolute-Value and
Factorial
Operator Type Resolution</title>
<title>Absolute-Value and
Negation
Operator Type Resolution</title>
<para>
The <productname>PostgreSQL</productname> operator catalog has several
...
...
@@ -437,6 +437,30 @@ SELECT @ '-4.5e500' AS "abs";
ERROR: "-4.5e500" is out of range for type double precision
</screen>
</para>
<para>
On the other hand, the prefix operator <literal>~</> (bitwise negation)
is defined only for integer data types, not for <type>float8</type>. So, if we
try a similar case with <literal>~</>, we get:
<screen>
SELECT ~ '20' AS "negation";
ERROR: operator is not unique: ~ "unknown"
HINT: Could not choose a best candidate operator. You may need to add explicit
type casts.
</screen>
This happens because the system can't decide which of the several
possible <literal>~</> operators should be preferred. We can help
it out with an explicit cast:
<screen>
SELECT ~ CAST('20' AS int8) AS "negation";
negation
----------
-21
(1 row)
</screen>
</para>
</example>
</sect1>
...
...
src/backend/utils/adt/numeric.c
View file @
145d9fa4
...
...
@@ -14,7 +14,7 @@
* Copyright (c) 1998-2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.
69 2003/12/01 21:52:37 momjian
Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.
70 2003/12/02 00:26:59 tgl
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -1290,49 +1290,39 @@ numeric_larger(PG_FUNCTION_ARGS)
/*
* numeric_fac()
* Computer factorial
*
* Compute factorial
*/
Datum
numeric_fac
(
PG_FUNCTION_ARGS
)
{
int64
num
=
PG_GETARG_INT64
(
0
);
Numeric
Var
count
;
Numeric
res
;
NumericVar
fact
;
NumericVar
zerovar
;
NumericVar
result
;
Numeric
res
;
if
(
num
<
1
)
{
if
(
num
<=
1
)
{
res
=
make_result
(
&
const_one
);
PG_RETURN_NUMERIC
(
res
);
}
init_var
(
&
fact
);
init_var
(
&
count
);
init_var
(
&
result
);
init_var
(
&
zerovar
);
zero_var
(
&
zerovar
);
int8_to_numericvar
((
int64
)
num
,
&
result
);
set_var_from_var
(
&
const_one
,
&
count
);
for
(
num
=
num
-
1
;
num
>
0
;
num
--
)
{
set_var_from_var
(
&
result
,
&
count
);
int8_to_numericvar
(
num
,
&
result
);
int8_to_numericvar
((
int64
)
num
,
&
fact
);
for
(
num
=
num
-
1
;
num
>
1
;
num
--
)
{
int8_to_numericvar
(
num
,
&
fact
);
mul_var
(
&
count
,
&
fact
,
&
result
,
count
.
dscale
+
fact
.
dscale
);
mul_var
(
&
result
,
&
fact
,
&
result
,
0
);
}
res
=
make_result
(
&
coun
t
);
res
=
make_result
(
&
resul
t
);
free_var
(
&
count
);
free_var
(
&
fact
);
free_var
(
&
result
);
free_var
(
&
zerovar
);
PG_RETURN_NUMERIC
(
res
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment