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

Commite15c384

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 parent9e7d87c commite15c384

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
@@ -9370,7 +9370,7 @@ power_var_int(const NumericVar *base, int exp, NumericVar *result, int rscale)
93709370
* to around log10(abs(exp)) digits, so work with this many extra digits
93719371
* of precision (plus a few more for good measure).
93729372
*/
9373-
sig_digits+= (int)log(Abs(exp))+8;
9373+
sig_digits+= (int)log(fabs(exp))+8;
93749374

93759375
/*
93769376
* 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
@@ -1674,6 +1674,12 @@ select 0.12 ^ (-20);
16741674
2608405330458882702.5529619561355838
16751675
(1 row)
16761676

1677+
select 1.000000000123 ^ (-2147483648);
1678+
?column?
1679+
--------------------
1680+
0.7678656556403084
1681+
(1 row)
1682+
16771683
-- cases that used to error out
16781684
select 0.12 ^ (-25);
16791685
?column?

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ select 3.789 ^ 21;
909909
select3.789 ^35;
910910
select1.2 ^345;
911911
select0.12 ^ (-20);
912+
select1.000000000123 ^ (-2147483648);
912913

913914
-- cases that used to error out
914915
select0.12 ^ (-25);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp