musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
path: root/src/math/scalbnl.c
diff options
context:
space:
mode:
authorSzabolcs Nagy <nsz@port70.net>2017年04月03日 02:38:13 +0200
committerRich Felker <dalias@aerifal.cx>2017年04月21日 17:31:00 -0400
commit8c44a060243f04283ca68dad199aab90336141db (patch)
tree5fd8fd700ac059c1ef2f2999c5783207c91bcf59 /src/math/scalbnl.c
parent2577b1bc16124d0690b9dd268a9f582f80bdcd67 (diff)
downloadmusl-8c44a060243f04283ca68dad199aab90336141db.tar.gz
fix scalbn when result is in the subnormal range
in nearest rounding mode scalbn could introduce double rounding error when an intermediate value and the final result were both in the subnormal range e.g. scalbn(0x1.7ffffffffffffp-1, -1073) returned 0x1p-1073 instead of 0x1p-1074, because the intermediate computation got rounded to 0x1.8p-1023. with the fix an intermediate value can only be in the subnormal range if the final result is 0 which is correct even after double rounding. (there still can be two roundings so signals may be raised twice, but that's only observable with trapping exceptions which is not supported.)
Diffstat (limited to 'src/math/scalbnl.c')
-rw-r--r--src/math/scalbnl.c 8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/math/scalbnl.c b/src/math/scalbnl.c
index 08a4c587..db44dab0 100644
--- a/src/math/scalbnl.c
+++ b/src/math/scalbnl.c
@@ -20,11 +20,11 @@ long double scalbnl(long double x, int n)
n = 16383;
}
} else if (n < -16382) {
- x *= 0x1p-16382L;
- n += 16382;
+ x *= 0x1p-16382L * 0x1p113L;
+ n += 16382 - 113;
if (n < -16382) {
- x *= 0x1p-16382L;
- n += 16382;
+ x *= 0x1p-16382L * 0x1p113L;
+ n += 16382 - 113;
if (n < -16382)
n = -16382;
}
generated by cgit v1.2.1 (git 2.18.0) at 2025年10月08日 05:53:34 +0000

AltStyle によって変換されたページ (->オリジナル) /