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

Commit258b770

Browse files
committed
Fix numeric_power() when the exponent is INT_MIN.
In power_var_int(), the computation of the number of significantdigits to use in the computation used log(Abs(exp)), which isn't safebecause Abs(exp) returns INT_MIN when exp is INT_MIN. Use fabs()instead of Abs(), so that the exponent is cast to a double before theabsolute value is taken.Back-patch to 9.6, where this was introduced (by7d9a473).Discussion:https://postgr.es/m/CAEZATCVd6pMkz=BrZEgBKyqqJrt2xghr=fNc8+Z=5xC6cgWrWA@mail.gmail.com
1 parent7c98759 commit258b770

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8601,7 +8601,7 @@ power_var_int(const NumericVar *base, int exp, NumericVar *result, int rscale)
86018601
* to around log10(abs(exp)) digits, so work with this many extra digits
86028602
* of precision (plus a few more for good measure).
86038603
*/
8604-
sig_digits+= (int)log(Abs(exp))+8;
8604+
sig_digits+= (int)log(fabs(exp))+8;
86058605

86068606
/*
86078607
* Now we can proceed with the multiplications.

‎src/test/regress/expected/numeric.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,12 @@ select 0.12 ^ (-20);
16231623
2608405330458882702.5529619561355838
16241624
(1 row)
16251625

1626+
select 1.000000000123 ^ (-2147483648);
1627+
?column?
1628+
--------------------
1629+
0.7678656556403084
1630+
(1 row)
1631+
16261632
-- cases that used to error out
16271633
select 0.12 ^ (-25);
16281634
?column?

‎src/test/regress/sql/numeric.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ select 3.789 ^ 21;
896896
select3.789 ^35;
897897
select1.2 ^345;
898898
select0.12 ^ (-20);
899+
select1.000000000123 ^ (-2147483648);
899900

900901
-- cases that used to error out
901902
select0.12 ^ (-25);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp