Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5248a2d

Browse files
author
Stefan Krah
committed
Enumerate all cases in the overflow detection strategy in mpd_qlog10().
1 parent f6f5618 commit 5248a2d

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

Modules/_decimal/libmpdec/mpdecimal.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4793,12 +4793,25 @@ mpd_qlog10(mpd_t *result, const mpd_t *a, const mpd_context_t *ctx,
47934793
mpd_qfinalize(result, &workctx, status);
47944794
return;
47954795
}
4796-
/* Check if the result will overflow.
4796+
/*
4797+
* Check if the result will overflow (0 < x, x != 1):
4798+
* 1) log10(x) < 0 iff adjexp(x) < 0
4799+
* 2) 0 < x /\ x <= y ==> adjexp(x) <= adjexp(y)
4800+
* 3) adjexp(x) <= log10(x) < adjexp(x) + 1
47974801
*
4798-
* 1) adjexp(a) + 1 > log10(a) >= adjexp(a)
4802+
* Case adjexp(x) >= 0:
4803+
* 4) adjexp(x) <= abs(log10(x))
4804+
* Case adjexp(x) > 0:
4805+
* 5) adjexp(adjexp(x)) <= adjexp(abs(log10(x)))
4806+
* Case adjexp(x) == 0:
4807+
* mpd_exp_digits(t)-1 == 0 <= emax (the shortcut is not triggered)
47994808
*
4800-
* 2) |log10(a)| >= adjexp(a), if adjexp(a) >= 0
4801-
* |log10(a)| > -adjexp(a)-1, if adjexp(a) < 0
4809+
* Case adjexp(x) < 0:
4810+
* 6) -adjexp(x) - 1 < abs(log10(x))
4811+
* Case adjexp(x) < -1:
4812+
* 7) adjexp(-adjexp(x) - 1) <= adjexp(abs(log(x)))
4813+
* Case adjexp(x) == -1:
4814+
* mpd_exp_digits(t)-1 == 0 <= emax (the shortcut is not triggered)
48024815
*/
48034816
adjexp = mpd_adjexp(a);
48044817
t = (adjexp < 0) ? -adjexp-1 : adjexp;

0 commit comments

Comments
 (0)