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

Commitbc43b7c

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 parent5a3574d commitbc43b7c

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

1029510295
/*
1029610296
* 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
@@ -2321,6 +2321,12 @@ select 0.12 ^ (-20);
23212321
2608405330458882702.5529619561355838
23222322
(1 row)
23232323

2324+
select 1.000000000123 ^ (-2147483648);
2325+
?column?
2326+
--------------------
2327+
0.7678656556403084
2328+
(1 row)
2329+
23242330
-- cases that used to error out
23252331
select 0.12 ^ (-25);
23262332
?column?

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,7 @@ select 3.789 ^ 21;
10891089
select3.789 ^35;
10901090
select1.2 ^345;
10911091
select0.12 ^ (-20);
1092+
select1.000000000123 ^ (-2147483648);
10921093

10931094
-- cases that used to error out
10941095
select0.12 ^ (-25);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp