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
4a586bd4
Commit
4a586bd4
authored
May 08, 2008
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add regression test for various power expressions with a zero base, and
adjust source code to be more modular.
parent
6b4e9d16
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
16 deletions
+25
-16
src/backend/utils/adt/numeric.c
src/backend/utils/adt/numeric.c
+17
-16
src/test/regress/expected/float8.out
src/test/regress/expected/float8.out
+6
-0
src/test/regress/sql/float8.sql
src/test/regress/sql/float8.sql
+2
-0
No files found.
src/backend/utils/adt/numeric.c
View file @
4a586bd4
...
...
@@ -14,7 +14,7 @@
* Copyright (c) 1998-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.11
1 2008/05/08 19:25:38
momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.11
2 2008/05/08 22:17:54
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -5170,21 +5170,6 @@ power_var(NumericVar *base, NumericVar *exp, NumericVar *result)
int
local_rscale
;
double
val
;
/*
* This avoids log(0) for cases of 0 raised to a non-integer.
* Also, while 0 ^ 0 can be either 1 or indeterminate (error), we
* treat it as one because most programming languages do this.
* http://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_zero_power
*/
if
(
cmp_var
(
base
,
&
const_zero
)
==
0
)
{
if
(
cmp_var
(
exp
,
&
const_zero
)
==
0
)
set_var_from_var
(
&
const_one
,
result
);
else
set_var_from_var
(
&
const_zero
,
result
);
return
;
}
/* If exp can be represented as an integer, use power_var_int */
if
(
exp
->
ndigits
==
0
||
exp
->
ndigits
<=
exp
->
weight
+
1
)
{
...
...
@@ -5217,6 +5202,17 @@ power_var(NumericVar *base, NumericVar *exp, NumericVar *result)
free_var
(
&
x
);
}
/*
* This avoids log(0) for cases of 0 raised to a non-integer.
* 0 ^ 0 handled by power_var_int().
*/
if
(
cmp_var
(
base
,
&
const_zero
)
==
0
)
{
set_var_from_var
(
&
const_zero
,
result
);
result
->
dscale
=
NUMERIC_MIN_SIG_DIGITS
;
/* no need to round */
return
;
}
init_var
(
&
ln_base
);
init_var
(
&
ln_num
);
...
...
@@ -5284,6 +5280,11 @@ power_var_int(NumericVar *base, int exp, NumericVar *result, int rscale)
switch
(
exp
)
{
case
0
:
/*
* While 0 ^ 0 can be either 1 or indeterminate (error), we
* treat it as 1 because most programming languages do this.
* http://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_zero_power
*/
set_var_from_var
(
&
const_one
,
result
);
result
->
dscale
=
rscale
;
/* no need to round */
return
;
...
...
src/test/regress/expected/float8.out
View file @
4a586bd4
...
...
@@ -349,6 +349,12 @@ SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f;
ERROR: value out of range: overflow
SELECT '' AS bad, f.f1 ^ '1e200' from FLOAT8_TBL f;
ERROR: value out of range: overflow
SELECT 0 ^ 0 + 0 ^ 1 + 0 ^ 0.0 + 0 ^ 0.5;
?column?
----------
2
(1 row)
SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 = '0.0' ;
ERROR: cannot take logarithm of zero
SELECT '' AS bad, ln(f.f1) from FLOAT8_TBL f where f.f1 < '0.0' ;
...
...
src/test/regress/sql/float8.sql
View file @
4a586bd4
...
...
@@ -129,6 +129,8 @@ SELECT '' AS bad, f.f1 * '1e200' from FLOAT8_TBL f;
SELECT
''
AS
bad
,
f
.
f1
^
'1e200'
from
FLOAT8_TBL
f
;
SELECT
0
^
0
+
0
^
1
+
0
^
0
.
0
+
0
^
0
.
5
;
SELECT
''
AS
bad
,
ln
(
f
.
f1
)
from
FLOAT8_TBL
f
where
f
.
f1
=
'0.0'
;
SELECT
''
AS
bad
,
ln
(
f
.
f1
)
from
FLOAT8_TBL
f
where
f
.
f1
<
'0.0'
;
...
...
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