commit 50422d5c37e85f08da7579cbffb4c0281a5cb2a8 (tree)
parent 962903e0fa222ee002355832e17144f66ec8d6ec
Author: Alex Rønne Petersen <alex@alexrp.com>
Date: Mon, 5 Jan 2026 15:49:55 +0100
Merge pull request 'libc: remove most symbols already present in compiler_rt' (#30648) from mercenary/zig:2879-rt into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30648
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
Diffstat:
25 files changed, 357 insertions(+), 1335 deletions(-)
diff --git a/lib/compiler_rt/exp.zig b/lib/compiler_rt/exp.zig
@@ -134,14 +134,11 @@ pub fn exp(x_: f64) callconv(.c) f64 {
}
if (x > 709.782712893383973096) {
// overflow if x != inf
- if (!math.isInf(x)) {
- math.raiseOverflow();
- }
- return math.inf(f64);
+ return if (common.want_float_exceptions) x * 0x1p1023 else std.math.inf(f64);
}
if (x < -708.39641853226410622) {
// underflow if x != -inf
- // if (common.want_float_exceptions) mem.doNotOptimizeAway(@as(f32, -0x1.0p-149 / x));
+ if (common.want_float_exceptions) mem.doNotOptimizeAway(-0x0.0000000000001p-1022 / x);
if (x < -745.13321910194110842) {
return 0;
}
@@ -174,7 +171,7 @@ pub fn exp(x_: f64) callconv(.c) f64 {
lo = 0;
} else {
// inexact if x != 0
- // if (common.want_float_exceptions) mem.doNotOptimizeAway(0x1.0p1023 + x);
+ if (common.want_float_exceptions) mem.doNotOptimizeAway(0x1.0p1023 + x);
return 1 + x;
}
diff --git a/lib/compiler_rt/exp2.zig b/lib/compiler_rt/exp2.zig
@@ -108,8 +108,7 @@ pub fn exp2(x: f64) callconv(.c) f64 {
if (ix >= 0x408FF000) {
// x >= 1024 or nan
if (ix >= 0x40900000 and ux >> 63 == 0) {
- math.raiseOverflow();
- return math.inf(f64);
+ return if (common.want_float_exceptions) x * 0x1p1023 else std.math.inf(f64);
}
// -inf or -nan
if (ix >= 0x7FF00000) {
diff --git a/lib/compiler_rt/log.zig b/lib/compiler_rt/log.zig
@@ -1,8 +1,8 @@
//! Ported from musl, which is licensed under the MIT license:
//! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//!
-//! https://git.musl-libc.org/cgit/musl/tree/src/math/lnf.c
-//! https://git.musl-libc.org/cgit/musl/tree/src/math/ln.c
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/logf.c?h=2d7d05f031e014068a61d3076c6178513395d2ae
+//! https://git.musl-libc.org/cgit/musl/tree/src/math/log.c?h=1b76ff0767d01df72f692806ee5adee13c67ef88
const std = @import("std");
const builtin = @import("builtin");
@@ -45,11 +45,11 @@ pub fn logf(x_: f32) callconv(.c) f32 {
if (ix < 0x00800000 or ix >> 31 != 0) {
// log(+-0) = -inf
if (ix << 1 == 0) {
- return -math.inf(f32);
+ return if (common.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64);
}
// log(-#) = nan
if (ix >> 31 != 0) {
- return math.nan(f32);
+ return if (common.want_float_exceptions) (x - x) / 0.0 else math.nan(f64);
}
// subnormal, scale x
@@ -81,60 +81,355 @@ pub fn logf(x_: f32) callconv(.c) f32 {
return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
}
-pub fn log(x_: f64) callconv(.c) f64 {
- const ln2_hi: f64 = 6.93147180369123816490e-01;
- const ln2_lo: f64 = 1.90821492927058770002e-10;
- const Lg1: f64 = 6.666666666666735130e-01;
- const Lg2: f64 = 3.999999999940941908e-01;
- const Lg3: f64 = 2.857142874366239149e-01;
- const Lg4: f64 = 2.222219843214978396e-01;
- const Lg5: f64 = 1.818357216161805012e-01;
- const Lg6: f64 = 1.531383769920937332e-01;
- const Lg7: f64 = 1.479819860511658591e-01;
+pub fn log(x: f64) callconv(.c) f64 {
+ const poly1 = [_]f64{
+ -0x1p-1,
+ 0x1.5555555555577p-2,
+ -0x1.ffffffffffdcbp-3,
+ 0x1.999999995dd0cp-3,
+ -0x1.55555556745a7p-3,
+ 0x1.24924a344de3p-3,
+ -0x1.fffffa4423d65p-4,
+ 0x1.c7184282ad6cap-4,
+ -0x1.999eb43b068ffp-4,
+ 0x1.78182f7afd085p-4,
+ -0x1.5521375d145cdp-4,
+ };
- var x = x_;
- var ix: u64 = @bitCast(x);
- var hx: u32 = @intCast(ix >> 32);
- var k: i32 = 0;
+ const poly = [_]f64{
+ -0x1.0000000000001p-1,
+ 0x1.555555551305bp-2,
+ -0x1.fffffffeb459p-3,
+ 0x1.999b324f10111p-3,
+ -0x1.55575e506c89fp-3,
+ };
- if (hx < 0x00100000 or hx >> 31 != 0) {
- // log(+-0) = -inf
- if (ix << 1 == 0) {
- return -math.inf(f64);
- }
- // log(-#) = nan
- if (hx >> 31 != 0) {
- return math.nan(f64);
+ const tab = [128]struct { invc: f64, logc: f64 }{
+ .{ .invc = 0x1.734f0c3e0de9fp+0, .logc = -0x1.7cc7f79e69000p-2 },
+ .{ .invc = 0x1.713786a2ce91fp+0, .logc = -0x1.76feec20d0000p-2 },
+ .{ .invc = 0x1.6f26008fab5a0p+0, .logc = -0x1.713e31351e000p-2 },
+ .{ .invc = 0x1.6d1a61f138c7dp+0, .logc = -0x1.6b85b38287800p-2 },
+ .{ .invc = 0x1.6b1490bc5b4d1p+0, .logc = -0x1.65d5590807800p-2 },
+ .{ .invc = 0x1.69147332f0cbap+0, .logc = -0x1.602d076180000p-2 },
+ .{ .invc = 0x1.6719f18224223p+0, .logc = -0x1.5a8ca86909000p-2 },
+ .{ .invc = 0x1.6524f99a51ed9p+0, .logc = -0x1.54f4356035000p-2 },
+ .{ .invc = 0x1.63356aa8f24c4p+0, .logc = -0x1.4f637c36b4000p-2 },
+ .{ .invc = 0x1.614b36b9ddc14p+0, .logc = -0x1.49da7fda85000p-2 },
+ .{ .invc = 0x1.5f66452c65c4cp+0, .logc = -0x1.445923989a800p-2 },
+ .{ .invc = 0x1.5d867b5912c4fp+0, .logc = -0x1.3edf439b0b800p-2 },
+ .{ .invc = 0x1.5babccb5b90dep+0, .logc = -0x1.396ce448f7000p-2 },
+ .{ .invc = 0x1.59d61f2d91a78p+0, .logc = -0x1.3401e17bda000p-2 },
+ .{ .invc = 0x1.5805612465687p+0, .logc = -0x1.2e9e2ef468000p-2 },
+ .{ .invc = 0x1.56397cee76bd3p+0, .logc = -0x1.2941b3830e000p-2 },
+ .{ .invc = 0x1.54725e2a77f93p+0, .logc = -0x1.23ec58cda8800p-2 },
+ .{ .invc = 0x1.52aff42064583p+0, .logc = -0x1.1e9e129279000p-2 },
+ .{ .invc = 0x1.50f22dbb2bddfp+0, .logc = -0x1.1956d2b48f800p-2 },
+ .{ .invc = 0x1.4f38f4734ded7p+0, .logc = -0x1.141679ab9f800p-2 },
+ .{ .invc = 0x1.4d843cfde2840p+0, .logc = -0x1.0edd094ef9800p-2 },
+ .{ .invc = 0x1.4bd3ec078a3c8p+0, .logc = -0x1.09aa518db1000p-2 },
+ .{ .invc = 0x1.4a27fc3e0258ap+0, .logc = -0x1.047e65263b800p-2 },
+ .{ .invc = 0x1.4880524d48434p+0, .logc = -0x1.feb224586f000p-3 },
+ .{ .invc = 0x1.46dce1b192d0bp+0, .logc = -0x1.f474a7517b000p-3 },
+ .{ .invc = 0x1.453d9d3391854p+0, .logc = -0x1.ea4443d103000p-3 },
+ .{ .invc = 0x1.43a2744b4845ap+0, .logc = -0x1.e020d44e9b000p-3 },
+ .{ .invc = 0x1.420b54115f8fbp+0, .logc = -0x1.d60a22977f000p-3 },
+ .{ .invc = 0x1.40782da3ef4b1p+0, .logc = -0x1.cc00104959000p-3 },
+ .{ .invc = 0x1.3ee8f5d57fe8fp+0, .logc = -0x1.c202956891000p-3 },
+ .{ .invc = 0x1.3d5d9a00b4ce9p+0, .logc = -0x1.b81178d811000p-3 },
+ .{ .invc = 0x1.3bd60c010c12bp+0, .logc = -0x1.ae2c9ccd3d000p-3 },
+ .{ .invc = 0x1.3a5242b75dab8p+0, .logc = -0x1.a45402e129000p-3 },
+ .{ .invc = 0x1.38d22cd9fd002p+0, .logc = -0x1.9a877681df000p-3 },
+ .{ .invc = 0x1.3755bc5847a1cp+0, .logc = -0x1.90c6d69483000p-3 },
+ .{ .invc = 0x1.35dce49ad36e2p+0, .logc = -0x1.87120a645c000p-3 },
+ .{ .invc = 0x1.34679984dd440p+0, .logc = -0x1.7d68fb4143000p-3 },
+ .{ .invc = 0x1.32f5cceffcb24p+0, .logc = -0x1.73cb83c627000p-3 },
+ .{ .invc = 0x1.3187775a10d49p+0, .logc = -0x1.6a39a9b376000p-3 },
+ .{ .invc = 0x1.301c8373e3990p+0, .logc = -0x1.60b3154b7a000p-3 },
+ .{ .invc = 0x1.2eb4ebb95f841p+0, .logc = -0x1.5737d76243000p-3 },
+ .{ .invc = 0x1.2d50a0219a9d1p+0, .logc = -0x1.4dc7b8fc23000p-3 },
+ .{ .invc = 0x1.2bef9a8b7fd2ap+0, .logc = -0x1.4462c51d20000p-3 },
+ .{ .invc = 0x1.2a91c7a0c1babp+0, .logc = -0x1.3b08abc830000p-3 },
+ .{ .invc = 0x1.293726014b530p+0, .logc = -0x1.31b996b490000p-3 },
+ .{ .invc = 0x1.27dfa5757a1f5p+0, .logc = -0x1.2875490a44000p-3 },
+ .{ .invc = 0x1.268b39b1d3bbfp+0, .logc = -0x1.1f3b9f879a000p-3 },
+ .{ .invc = 0x1.2539d838ff5bdp+0, .logc = -0x1.160c8252ca000p-3 },
+ .{ .invc = 0x1.23eb7aac9083bp+0, .logc = -0x1.0ce7f57f72000p-3 },
+ .{ .invc = 0x1.22a012ba940b6p+0, .logc = -0x1.03cdc49fea000p-3 },
+ .{ .invc = 0x1.2157996cc4132p+0, .logc = -0x1.f57bdbc4b8000p-4 },
+ .{ .invc = 0x1.201201dd2fc9bp+0, .logc = -0x1.e370896404000p-4 },
+ .{ .invc = 0x1.1ecf4494d480bp+0, .logc = -0x1.d17983ef94000p-4 },
+ .{ .invc = 0x1.1d8f5528f6569p+0, .logc = -0x1.bf9674ed8a000p-4 },
+ .{ .invc = 0x1.1c52311577e7cp+0, .logc = -0x1.adc79202f6000p-4 },
+ .{ .invc = 0x1.1b17c74cb26e9p+0, .logc = -0x1.9c0c3e7288000p-4 },
+ .{ .invc = 0x1.19e010c2c1ab6p+0, .logc = -0x1.8a646b372c000p-4 },
+ .{ .invc = 0x1.18ab07bb670bdp+0, .logc = -0x1.78d01b3ac0000p-4 },
+ .{ .invc = 0x1.1778a25efbcb6p+0, .logc = -0x1.674f145380000p-4 },
+ .{ .invc = 0x1.1648d354c31dap+0, .logc = -0x1.55e0e6d878000p-4 },
+ .{ .invc = 0x1.151b990275fddp+0, .logc = -0x1.4485cdea1e000p-4 },
+ .{ .invc = 0x1.13f0ea432d24cp+0, .logc = -0x1.333d94d6aa000p-4 },
+ .{ .invc = 0x1.12c8b7210f9dap+0, .logc = -0x1.22079f8c56000p-4 },
+ .{ .invc = 0x1.11a3028ecb531p+0, .logc = -0x1.10e4698622000p-4 },
+ .{ .invc = 0x1.107fbda8434afp+0, .logc = -0x1.ffa6c6ad20000p-5 },
+ .{ .invc = 0x1.0f5ee0f4e6bb3p+0, .logc = -0x1.dda8d4a774000p-5 },
+ .{ .invc = 0x1.0e4065d2a9fcep+0, .logc = -0x1.bbcece4850000p-5 },
+ .{ .invc = 0x1.0d244632ca521p+0, .logc = -0x1.9a1894012c000p-5 },
+ .{ .invc = 0x1.0c0a77ce2981ap+0, .logc = -0x1.788583302c000p-5 },
+ .{ .invc = 0x1.0af2f83c636d1p+0, .logc = -0x1.5715e67d68000p-5 },
+ .{ .invc = 0x1.09ddb98a01339p+0, .logc = -0x1.35c8a49658000p-5 },
+ .{ .invc = 0x1.08cabaf52e7dfp+0, .logc = -0x1.149e364154000p-5 },
+ .{ .invc = 0x1.07b9f2f4e28fbp+0, .logc = -0x1.e72c082eb8000p-6 },
+ .{ .invc = 0x1.06ab58c358f19p+0, .logc = -0x1.a55f152528000p-6 },
+ .{ .invc = 0x1.059eea5ecf92cp+0, .logc = -0x1.63d62cf818000p-6 },
+ .{ .invc = 0x1.04949cdd12c90p+0, .logc = -0x1.228fb8caa0000p-6 },
+ .{ .invc = 0x1.038c6c6f0ada9p+0, .logc = -0x1.c317b20f90000p-7 },
+ .{ .invc = 0x1.02865137932a9p+0, .logc = -0x1.419355daa0000p-7 },
+ .{ .invc = 0x1.0182427ea7348p+0, .logc = -0x1.81203c2ec0000p-8 },
+ .{ .invc = 0x1.008040614b195p+0, .logc = -0x1.0040979240000p-9 },
+ .{ .invc = 0x1.fe01ff726fa1ap-1, .logc = 0x1.feff384900000p-9 },
+ .{ .invc = 0x1.fa11cc261ea74p-1, .logc = 0x1.7dc41353d0000p-7 },
+ .{ .invc = 0x1.f6310b081992ep-1, .logc = 0x1.3cea3c4c28000p-6 },
+ .{ .invc = 0x1.f25f63ceeadcdp-1, .logc = 0x1.b9fc114890000p-6 },
+ .{ .invc = 0x1.ee9c8039113e7p-1, .logc = 0x1.1b0d8ce110000p-5 },
+ .{ .invc = 0x1.eae8078cbb1abp-1, .logc = 0x1.58a5bd001c000p-5 },
+ .{ .invc = 0x1.e741aa29d0c9bp-1, .logc = 0x1.95c8340d88000p-5 },
+ .{ .invc = 0x1.e3a91830a99b5p-1, .logc = 0x1.d276aef578000p-5 },
+ .{ .invc = 0x1.e01e009609a56p-1, .logc = 0x1.07598e598c000p-4 },
+ .{ .invc = 0x1.dca01e577bb98p-1, .logc = 0x1.253f5e30d2000p-4 },
+ .{ .invc = 0x1.d92f20b7c9103p-1, .logc = 0x1.42edd8b380000p-4 },
+ .{ .invc = 0x1.d5cac66fb5ccep-1, .logc = 0x1.606598757c000p-4 },
+ .{ .invc = 0x1.d272caa5ede9dp-1, .logc = 0x1.7da76356a0000p-4 },
+ .{ .invc = 0x1.cf26e3e6b2ccdp-1, .logc = 0x1.9ab434e1c6000p-4 },
+ .{ .invc = 0x1.cbe6da2a77902p-1, .logc = 0x1.b78c7bb0d6000p-4 },
+ .{ .invc = 0x1.c8b266d37086dp-1, .logc = 0x1.d431332e72000p-4 },
+ .{ .invc = 0x1.c5894bd5d5804p-1, .logc = 0x1.f0a3171de6000p-4 },
+ .{ .invc = 0x1.c26b533bb9f8cp-1, .logc = 0x1.067152b914000p-3 },
+ .{ .invc = 0x1.bf583eeece73fp-1, .logc = 0x1.147858292b000p-3 },
+ .{ .invc = 0x1.bc4fd75db96c1p-1, .logc = 0x1.2266ecdca3000p-3 },
+ .{ .invc = 0x1.b951e0c864a28p-1, .logc = 0x1.303d7a6c55000p-3 },
+ .{ .invc = 0x1.b65e2c5ef3e2cp-1, .logc = 0x1.3dfc33c331000p-3 },
+ .{ .invc = 0x1.b374867c9888bp-1, .logc = 0x1.4ba366b7a8000p-3 },
+ .{ .invc = 0x1.b094b211d304ap-1, .logc = 0x1.5933928d1f000p-3 },
+ .{ .invc = 0x1.adbe885f2ef7ep-1, .logc = 0x1.66acd2418f000p-3 },
+ .{ .invc = 0x1.aaf1d31603da2p-1, .logc = 0x1.740f8ec669000p-3 },
+ .{ .invc = 0x1.a82e63fd358a7p-1, .logc = 0x1.815c0f51af000p-3 },
+ .{ .invc = 0x1.a5740ef09738bp-1, .logc = 0x1.8e92954f68000p-3 },
+ .{ .invc = 0x1.a2c2a90ab4b27p-1, .logc = 0x1.9bb3602f84000p-3 },
+ .{ .invc = 0x1.a01a01393f2d1p-1, .logc = 0x1.a8bed1c2c0000p-3 },
+ .{ .invc = 0x1.9d79f24db3c1bp-1, .logc = 0x1.b5b515c01d000p-3 },
+ .{ .invc = 0x1.9ae2505c7b190p-1, .logc = 0x1.c2967ccbcc000p-3 },
+ .{ .invc = 0x1.9852ef297ce2fp-1, .logc = 0x1.cf635d5486000p-3 },
+ .{ .invc = 0x1.95cbaeea44b75p-1, .logc = 0x1.dc1bd3446c000p-3 },
+ .{ .invc = 0x1.934c69de74838p-1, .logc = 0x1.e8c01b8cfe000p-3 },
+ .{ .invc = 0x1.90d4f2f6752e6p-1, .logc = 0x1.f5509c0179000p-3 },
+ .{ .invc = 0x1.8e6528effd79dp-1, .logc = 0x1.00e6c121fb800p-2 },
+ .{ .invc = 0x1.8bfce9fcc007cp-1, .logc = 0x1.071b80e93d000p-2 },
+ .{ .invc = 0x1.899c0dabec30ep-1, .logc = 0x1.0d46b9e867000p-2 },
+ .{ .invc = 0x1.87427aa2317fbp-1, .logc = 0x1.13687334bd000p-2 },
+ .{ .invc = 0x1.84f00acb39a08p-1, .logc = 0x1.1980d67234800p-2 },
+ .{ .invc = 0x1.82a49e8653e55p-1, .logc = 0x1.1f8ffe0cc8000p-2 },
+ .{ .invc = 0x1.8060195f40260p-1, .logc = 0x1.2595fd7636800p-2 },
+ .{ .invc = 0x1.7e22563e0a329p-1, .logc = 0x1.2b9300914a800p-2 },
+ .{ .invc = 0x1.7beb377dcb5adp-1, .logc = 0x1.3187210436000p-2 },
+ .{ .invc = 0x1.79baa679725c2p-1, .logc = 0x1.377266dec1800p-2 },
+ .{ .invc = 0x1.77907f2170657p-1, .logc = 0x1.3d54ffbaf3000p-2 },
+ .{ .invc = 0x1.756cadbd6130cp-1, .logc = 0x1.432eee32fe000p-2 },
+ };
+
+ const tab2 = [128]struct { chi: f64, clo: f64 }{
+ .{ .chi = 0x1.61000014fb66bp-1, .clo = 0x1.e026c91425b3cp-56 },
+ .{ .chi = 0x1.63000034db495p-1, .clo = 0x1.dbfea48005d41p-55 },
+ .{ .chi = 0x1.650000d94d478p-1, .clo = 0x1.e7fa786d6a5b7p-55 },
+ .{ .chi = 0x1.67000074e6fadp-1, .clo = 0x1.1fcea6b54254cp-57 },
+ .{ .chi = 0x1.68ffffedf0faep-1, .clo = -0x1.c7e274c590efdp-56 },
+ .{ .chi = 0x1.6b0000763c5bcp-1, .clo = -0x1.ac16848dcda01p-55 },
+ .{ .chi = 0x1.6d0001e5cc1f6p-1, .clo = 0x1.33f1c9d499311p-55 },
+ .{ .chi = 0x1.6efffeb05f63ep-1, .clo = -0x1.e80041ae22d53p-56 },
+ .{ .chi = 0x1.710000e86978p-1, .clo = 0x1.bff6671097952p-56 },
+ .{ .chi = 0x1.72ffffc67e912p-1, .clo = 0x1.c00e226bd8724p-55 },
+ .{ .chi = 0x1.74fffdf81116ap-1, .clo = -0x1.e02916ef101d2p-57 },
+ .{ .chi = 0x1.770000f679c9p-1, .clo = -0x1.7fc71cd549c74p-57 },
+ .{ .chi = 0x1.78ffffa7ec835p-1, .clo = 0x1.1bec19ef50483p-55 },
+ .{ .chi = 0x1.7affffe20c2e6p-1, .clo = -0x1.07e1729cc6465p-56 },
+ .{ .chi = 0x1.7cfffed3fc9p-1, .clo = -0x1.08072087b8b1cp-55 },
+ .{ .chi = 0x1.7efffe9261a76p-1, .clo = 0x1.dc0286d9df9aep-55 },
+ .{ .chi = 0x1.81000049ca3e8p-1, .clo = 0x1.97fd251e54c33p-55 },
+ .{ .chi = 0x1.8300017932c8fp-1, .clo = -0x1.afee9b630f381p-55 },
+ .{ .chi = 0x1.850000633739cp-1, .clo = 0x1.9bfbf6b6535bcp-55 },
+ .{ .chi = 0x1.87000204289c6p-1, .clo = -0x1.bbf65f3117b75p-55 },
+ .{ .chi = 0x1.88fffebf57904p-1, .clo = -0x1.9006ea23dcb57p-55 },
+ .{ .chi = 0x1.8b00022bc04dfp-1, .clo = -0x1.d00df38e04b0ap-56 },
+ .{ .chi = 0x1.8cfffe50c1b8ap-1, .clo = -0x1.8007146ff9f05p-55 },
+ .{ .chi = 0x1.8effffc918e43p-1, .clo = 0x1.3817bd07a7038p-55 },
+ .{ .chi = 0x1.910001efa5fc7p-1, .clo = 0x1.93e9176dfb403p-55 },
+ .{ .chi = 0x1.9300013467bb9p-1, .clo = 0x1.f804e4b980276p-56 },
+ .{ .chi = 0x1.94fffe6ee076fp-1, .clo = -0x1.f7ef0d9ff622ep-55 },
+ .{ .chi = 0x1.96fffde3c12d1p-1, .clo = -0x1.082aa962638bap-56 },
+ .{ .chi = 0x1.98ffff4458a0dp-1, .clo = -0x1.7801b9164a8efp-55 },
+ .{ .chi = 0x1.9afffdd982e3ep-1, .clo = -0x1.740e08a5a9337p-55 },
+ .{ .chi = 0x1.9cfffed49fb66p-1, .clo = 0x1.fce08c19bep-60 },
+ .{ .chi = 0x1.9f00020f19c51p-1, .clo = -0x1.a3faa27885b0ap-55 },
+ .{ .chi = 0x1.a10001145b006p-1, .clo = 0x1.4ff489958da56p-56 },
+ .{ .chi = 0x1.a300007bbf6fap-1, .clo = 0x1.cbeab8a2b6d18p-55 },
+ .{ .chi = 0x1.a500010971d79p-1, .clo = 0x1.8fecadd78793p-55 },
+ .{ .chi = 0x1.a70001df52e48p-1, .clo = -0x1.f41763dd8abdbp-55 },
+ .{ .chi = 0x1.a90001c593352p-1, .clo = -0x1.ebf0284c27612p-55 },
+ .{ .chi = 0x1.ab0002a4f3e4bp-1, .clo = -0x1.9fd043cff3f5fp-57 },
+ .{ .chi = 0x1.acfffd7ae1ed1p-1, .clo = -0x1.23ee7129070b4p-55 },
+ .{ .chi = 0x1.aefffee510478p-1, .clo = 0x1.a063ee00edea3p-57 },
+ .{ .chi = 0x1.b0fffdb650d5bp-1, .clo = 0x1.a06c8381f0ab9p-58 },
+ .{ .chi = 0x1.b2ffffeaaca57p-1, .clo = -0x1.9011e74233c1dp-56 },
+ .{ .chi = 0x1.b4fffd995badcp-1, .clo = -0x1.9ff1068862a9fp-56 },
+ .{ .chi = 0x1.b7000249e659cp-1, .clo = 0x1.aff45d0864f3ep-55 },
+ .{ .chi = 0x1.b8ffff987164p-1, .clo = 0x1.cfe7796c2c3f9p-56 },
+ .{ .chi = 0x1.bafffd204cb4fp-1, .clo = -0x1.3ff27eef22bc4p-57 },
+ .{ .chi = 0x1.bcfffd2415c45p-1, .clo = -0x1.cffb7ee3bea21p-57 },
+ .{ .chi = 0x1.beffff86309dfp-1, .clo = -0x1.14103972e0b5cp-55 },
+ .{ .chi = 0x1.c0fffe1b57653p-1, .clo = 0x1.bc16494b76a19p-55 },
+ .{ .chi = 0x1.c2ffff1fa57e3p-1, .clo = -0x1.4feef8d30c6edp-57 },
+ .{ .chi = 0x1.c4fffdcbfe424p-1, .clo = -0x1.43f68bcec4775p-55 },
+ .{ .chi = 0x1.c6fffed54b9f7p-1, .clo = 0x1.47ea3f053e0ecp-55 },
+ .{ .chi = 0x1.c8fffeb998fd5p-1, .clo = 0x1.383068df992f1p-56 },
+ .{ .chi = 0x1.cb0002125219ap-1, .clo = -0x1.8fd8e64180e04p-57 },
+ .{ .chi = 0x1.ccfffdd94469cp-1, .clo = 0x1.e7ebe1cc7ea72p-55 },
+ .{ .chi = 0x1.cefffeafdc476p-1, .clo = 0x1.ebe39ad9f88fep-55 },
+ .{ .chi = 0x1.d1000169af82bp-1, .clo = 0x1.57d91a8b95a71p-56 },
+ .{ .chi = 0x1.d30000d0ff71dp-1, .clo = 0x1.9c1906970c7dap-55 },
+ .{ .chi = 0x1.d4fffea790fc4p-1, .clo = -0x1.80e37c558fe0cp-58 },
+ .{ .chi = 0x1.d70002edc87e5p-1, .clo = -0x1.f80d64dc10f44p-56 },
+ .{ .chi = 0x1.d900021dc82aap-1, .clo = -0x1.47c8f94fd5c5cp-56 },
+ .{ .chi = 0x1.dafffd86b0283p-1, .clo = 0x1.c7f1dc521617ep-55 },
+ .{ .chi = 0x1.dd000296c4739p-1, .clo = 0x1.8019eb2ffb153p-55 },
+ .{ .chi = 0x1.defffe54490f5p-1, .clo = 0x1.e00d2c652cc89p-57 },
+ .{ .chi = 0x1.e0fffcdabf694p-1, .clo = -0x1.f8340202d69d2p-56 },
+ .{ .chi = 0x1.e2fffdb52c8ddp-1, .clo = 0x1.b00c1ca1b0864p-56 },
+ .{ .chi = 0x1.e4ffff24216efp-1, .clo = 0x1.2ffa8b094ab51p-56 },
+ .{ .chi = 0x1.e6fffe88a5e11p-1, .clo = -0x1.7f673b1efbe59p-58 },
+ .{ .chi = 0x1.e9000119eff0dp-1, .clo = -0x1.4808d5e0bc801p-55 },
+ .{ .chi = 0x1.eafffdfa51744p-1, .clo = 0x1.80006d54320b5p-56 },
+ .{ .chi = 0x1.ed0001a127fa1p-1, .clo = -0x1.002f860565c92p-58 },
+ .{ .chi = 0x1.ef00007babcc4p-1, .clo = -0x1.540445d35e611p-55 },
+ .{ .chi = 0x1.f0ffff57a8d02p-1, .clo = -0x1.ffb3139ef9105p-59 },
+ .{ .chi = 0x1.f30001ee58ac7p-1, .clo = 0x1.a81acf2731155p-55 },
+ .{ .chi = 0x1.f4ffff5823494p-1, .clo = 0x1.a3f41d4d7c743p-55 },
+ .{ .chi = 0x1.f6ffffca94c6bp-1, .clo = -0x1.202f41c987875p-57 },
+ .{ .chi = 0x1.f8fffe1f9c441p-1, .clo = 0x1.77dd1f477e74bp-56 },
+ .{ .chi = 0x1.fafffd2e0e37ep-1, .clo = -0x1.f01199a7ca331p-57 },
+ .{ .chi = 0x1.fd0001c77e49ep-1, .clo = 0x1.181ee4bceacb1p-56 },
+ .{ .chi = 0x1.feffff7e0c331p-1, .clo = -0x1.e05370170875ap-57 },
+ .{ .chi = 0x1.00ffff465606ep+0, .clo = -0x1.a7ead491c0adap-55 },
+ .{ .chi = 0x1.02ffff3867a58p+0, .clo = -0x1.77f69c3fcb2ep-54 },
+ .{ .chi = 0x1.04ffffdfc0d17p+0, .clo = 0x1.7bffe34cb945bp-54 },
+ .{ .chi = 0x1.0700003cd4d82p+0, .clo = 0x1.20083c0e456cbp-55 },
+ .{ .chi = 0x1.08ffff9f2cbe8p+0, .clo = -0x1.dffdfbe37751ap-57 },
+ .{ .chi = 0x1.0b000010cda65p+0, .clo = -0x1.13f7faee626ebp-54 },
+ .{ .chi = 0x1.0d00001a4d338p+0, .clo = 0x1.07dfa79489ff7p-55 },
+ .{ .chi = 0x1.0effffadafdfdp+0, .clo = -0x1.7040570d66bcp-56 },
+ .{ .chi = 0x1.110000bbafd96p+0, .clo = 0x1.e80d4846d0b62p-55 },
+ .{ .chi = 0x1.12ffffae5f45dp+0, .clo = 0x1.dbffa64fd36efp-54 },
+ .{ .chi = 0x1.150000dd59ad9p+0, .clo = 0x1.a0077701250aep-54 },
+ .{ .chi = 0x1.170000f21559ap+0, .clo = 0x1.dfdf9e2e3deeep-55 },
+ .{ .chi = 0x1.18ffffc275426p+0, .clo = 0x1.10030dc3b7273p-54 },
+ .{ .chi = 0x1.1b000123d3c59p+0, .clo = 0x1.97f7980030188p-54 },
+ .{ .chi = 0x1.1cffff8299eb7p+0, .clo = -0x1.5f932ab9f8c67p-57 },
+ .{ .chi = 0x1.1effff48ad4p+0, .clo = 0x1.37fbf9da75bebp-54 },
+ .{ .chi = 0x1.210000c8b86a4p+0, .clo = 0x1.f806b91fd5b22p-54 },
+ .{ .chi = 0x1.2300003854303p+0, .clo = 0x1.3ffc2eb9fbf33p-54 },
+ .{ .chi = 0x1.24fffffbcf684p+0, .clo = 0x1.601e77e2e2e72p-56 },
+ .{ .chi = 0x1.26ffff52921d9p+0, .clo = 0x1.ffcbb767f0c61p-56 },
+ .{ .chi = 0x1.2900014933a3cp+0, .clo = -0x1.202ca3c02412bp-56 },
+ .{ .chi = 0x1.2b00014556313p+0, .clo = -0x1.2808233f21f02p-54 },
+ .{ .chi = 0x1.2cfffebfe523bp+0, .clo = -0x1.8ff7e384fdcf2p-55 },
+ .{ .chi = 0x1.2f0000bb8ad96p+0, .clo = -0x1.5ff51503041c5p-55 },
+ .{ .chi = 0x1.30ffffb7ae2afp+0, .clo = -0x1.10071885e289dp-55 },
+ .{ .chi = 0x1.32ffffeac5f7fp+0, .clo = -0x1.1ff5d3fb7b715p-54 },
+ .{ .chi = 0x1.350000ca66756p+0, .clo = 0x1.57f82228b82bdp-54 },
+ .{ .chi = 0x1.3700011fbf721p+0, .clo = 0x1.000bac40dd5ccp-55 },
+ .{ .chi = 0x1.38ffff9592fb9p+0, .clo = -0x1.43f9d2db2a751p-54 },
+ .{ .chi = 0x1.3b00004ddd242p+0, .clo = 0x1.57f6b707638e1p-55 },
+ .{ .chi = 0x1.3cffff5b2c957p+0, .clo = 0x1.a023a10bf1231p-56 },
+ .{ .chi = 0x1.3efffeab0b418p+0, .clo = 0x1.87f6d66b152bp-54 },
+ .{ .chi = 0x1.410001532aff4p+0, .clo = 0x1.7f8375f198524p-57 },
+ .{ .chi = 0x1.4300017478b29p+0, .clo = 0x1.301e672dc5143p-55 },
+ .{ .chi = 0x1.44fffe795b463p+0, .clo = 0x1.9ff69b8b2895ap-55 },
+ .{ .chi = 0x1.46fffe80475ep+0, .clo = -0x1.5c0b19bc2f254p-54 },
+ .{ .chi = 0x1.48fffef6fc1e7p+0, .clo = 0x1.b4009f23a2a72p-54 },
+ .{ .chi = 0x1.4afffe5bea704p+0, .clo = -0x1.4ffb7bf0d7d45p-54 },
+ .{ .chi = 0x1.4d000171027dep+0, .clo = -0x1.9c06471dc6a3dp-54 },
+ .{ .chi = 0x1.4f0000ff03ee2p+0, .clo = 0x1.77f890b85531cp-54 },
+ .{ .chi = 0x1.5100012dc4bd1p+0, .clo = 0x1.004657166a436p-57 },
+ .{ .chi = 0x1.530001605277ap+0, .clo = -0x1.6bfcece233209p-54 },
+ .{ .chi = 0x1.54fffecdb704cp+0, .clo = -0x1.902720505a1d7p-55 },
+ .{ .chi = 0x1.56fffef5f54a9p+0, .clo = 0x1.bbfe60ec96412p-54 },
+ .{ .chi = 0x1.5900017e61012p+0, .clo = 0x1.87ec581afef9p-55 },
+ .{ .chi = 0x1.5b00003c93e92p+0, .clo = -0x1.f41080abf0ccp-54 },
+ .{ .chi = 0x1.5d0001d4919bcp+0, .clo = -0x1.8812afb254729p-54 },
+ .{ .chi = 0x1.5efffe7b87a89p+0, .clo = -0x1.47eb780ed6904p-54 },
+ };
+
+ var ix: i64 = @bitCast(x);
+
+ const LO: i64 = @bitCast(@as(f64, 1.0 - 0x1p-4));
+ const HI: i64 = @bitCast(@as(f64, 1.0 + 0x1.09p-4));
+ if (LO <= ix and ix < HI) {
+ @branchHint(.unlikely);
+ if (ix == @as(i64, @bitCast(@as(f64, 1)))) {
+ @branchHint(.unlikely);
+ return 0;
}
- // subnormal, scale x
- k -= 54;
- x *= 0x1p54;
- hx = @intCast(@as(u64, @bitCast(x)) >> 32);
- } else if (hx >= 0x7FF00000) {
- return x;
- } else if (hx == 0x3FF00000 and ix << 32 == 0) {
- return 0;
+ const r = x - 1;
+ const r2 = r * r;
+ const r3 = r * r2;
+
+ const y = r3 * (poly1[1] + r * poly1[2] + r2 * poly1[3] +
+ r3 * (poly1[4] + r * poly1[5] + r2 * poly1[6] +
+ r3 * (poly1[7] + r * poly1[8] + r2 * poly1[9] + r3 * poly1[10])));
+
+ var w = r * 0x1p27;
+ const rhi = r + w - w;
+ const rlo = r - rhi;
+ w = rhi * rhi * poly1[0];
+ const hi = r + w;
+ const lo = r - hi + w + poly1[0] * rlo * (rhi + r);
+ return y + lo + hi;
}
+ const top = @as(u64, @bitCast(ix)) >> 48;
+ if (top < 0x0010 or 0x7ff0 <= top) {
+ @branchHint(.unlikely);
- // x into [sqrt(2) / 2, sqrt(2)]
- hx += 0x3FF00000 - 0x3FE6A09E;
- k += @as(i32, @intCast(hx >> 20)) - 0x3FF;
- hx = (hx & 0x000FFFFF) + 0x3FE6A09E;
- ix = (@as(u64, hx) << 32) | (ix & 0xFFFFFFFF);
- x = @bitCast(ix);
+ if (ix << 1 == 0)
+ return if (common.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64);
- const f = x - 1.0;
- const hfsq = 0.5 * f * f;
- const s = f / (2.0 + f);
- const z = s * s;
- const w = z * z;
- const t1 = w * (Lg2 + w * (Lg4 + w * Lg6));
- const t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));
- const R = t2 + t1;
- const dk: f64 = @floatFromInt(k);
+ if (ix == @as(i64, @bitCast(std.math.inf(f64))))
+ return x;
- return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
+ if (top & 0x8000 != 0 or top & 0x7ff0 == 0x7ff0)
+ return if (common.want_float_exceptions) (x - x) / 0.0 else math.nan(f64);
+
+ ix = @as(i64, @bitCast(x * 0x1p52)) - (52 << 52);
+ }
+
+ const tmp: packed struct(i64) { unused: u45, i: u7, k: i12 } = @bitCast(ix - 0x3fe6000000000000);
+ const i = tmp.i;
+ const k = tmp.k;
+ const iz = ix - (@as(i64, tmp.k) << 52);
+ const invc = tab[i].invc;
+ const logc = tab[i].logc;
+ const z: f64 = @bitCast(iz);
+
+ // maybe use fma as musl does
+ const r = (z - tab2[i].chi - tab2[i].clo) * invc;
+
+ // https://github.com/ziglang/zig/issues/18614
+ const kd: f64 = @floatFromInt(k);
+ const w = kd * 0x1.62e42fefa3800p-1 + logc;
+ const hi = w + r;
+ const lo = w - hi + r + kd * 0x1.ef35793c76730p-45;
+
+ const r2 = r * r;
+
+ const y = lo + r2 * poly[0] + r * r2 * (poly[1] + r * poly[2] + r2 * (poly[3] + r * poly[4])) + hi;
+ return @bitCast(y);
}
pub fn __logx(a: f80) callconv(.c) f80 {
diff --git a/lib/compiler_rt/log10.zig b/lib/compiler_rt/log10.zig
@@ -49,11 +49,11 @@ pub fn log10f(x_: f32) callconv(.c) f32 {
if (ix < 0x00800000 or ix >> 31 != 0) {
// log(+-0) = -inf
if (ix << 1 == 0) {
- return -math.inf(f32);
+ return if (common.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64);
}
// log(-#) = nan
if (ix >> 31 != 0) {
- return math.nan(f32);
+ return if (common.want_float_exceptions) (x - x) / 0.0 else math.nan(f64);
}
k -= 25;
@@ -111,11 +111,11 @@ pub fn log10(x_: f64) callconv(.c) f64 {
if (hx < 0x00100000 or hx >> 31 != 0) {
// log(+-0) = -inf
if (ix << 1 == 0) {
- return -math.inf(f64);
+ return if (common.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64);
}
// log(-#) = nan
if (hx >> 31 != 0) {
- return math.nan(f64);
+ return if (common.want_float_exceptions) (x - x) / 0.0 else math.nan(f64);
}
// subnormal, scale x
diff --git a/lib/compiler_rt/log2.zig b/lib/compiler_rt/log2.zig
@@ -47,11 +47,11 @@ pub fn log2f(x_: f32) callconv(.c) f32 {
if (ix < 0x00800000 or ix >> 31 != 0) {
// log(+-0) = -inf
if (ix << 1 == 0) {
- return -math.inf(f32);
+ return if (common.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64);
}
// log(-#) = nan
if (ix >> 31 != 0) {
- return math.nan(f32);
+ return if (common.want_float_exceptions) (x - x) / 0.0 else math.nan(f64);
}
k -= 25;
@@ -105,11 +105,11 @@ pub fn log2(x_: f64) callconv(.c) f64 {
if (hx < 0x00100000 or hx >> 31 != 0) {
// log(+-0) = -inf
if (ix << 1 == 0) {
- return -math.inf(f64);
+ return if (common.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64);
}
// log(-#) = nan
if (hx >> 31 != 0) {
- return math.nan(f64);
+ return if (common.want_float_exceptions) (x - x) / 0.0 else math.nan(f64);
}
// subnormal, scale x
diff --git a/lib/libc/mingw/math/expf.c b/lib/libc/mingw/math/expf.c
@@ -1,11 +0,0 @@
-/**
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is part of the mingw-w64 runtime package.
- * No warranty is given; refer to the file DISCLAIMER.PD within this package.
- */
-#include <math.h>
-
-float expf (float x)
-{
- return (float) exp (x);
-}
diff --git a/lib/libc/mingw/math/log10f.c b/lib/libc/mingw/math/log10f.c
@@ -1,11 +0,0 @@
-/**
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is part of the mingw-w64 runtime package.
- * No warranty is given; refer to the file DISCLAIMER.PD within this package.
- */
-#include <math.h>
-
-float log10f(float _X)
-{
- return ((float)log10((double)_X));
-}
diff --git a/lib/libc/mingw/math/logf.c b/lib/libc/mingw/math/logf.c
@@ -1,11 +0,0 @@
-/**
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is part of the mingw-w64 runtime package.
- * No warranty is given; refer to the file DISCLAIMER.PD within this package.
- */
-#include <math.h>
-
-float logf(float _X)
-{
- return ((float)log((double)_X));
-}
diff --git a/lib/libc/musl/src/math/exp.c b/lib/libc/musl/src/math/exp.c
@@ -1,134 +0,0 @@
-/*
- * Double-precision e^x function.
- *
- * Copyright (c) 2018, Arm Limited.
- * SPDX-License-Identifier: MIT
- */
-
-#include <math.h>
-#include <stdint.h>
-#include "libm.h"
-#include "exp_data.h"
-
-#define N (1 << EXP_TABLE_BITS)
-#define InvLn2N __exp_data.invln2N
-#define NegLn2hiN __exp_data.negln2hiN
-#define NegLn2loN __exp_data.negln2loN
-#define Shift __exp_data.shift
-#define T __exp_data.tab
-#define C2 __exp_data.poly[5 - EXP_POLY_ORDER]
-#define C3 __exp_data.poly[6 - EXP_POLY_ORDER]
-#define C4 __exp_data.poly[7 - EXP_POLY_ORDER]
-#define C5 __exp_data.poly[8 - EXP_POLY_ORDER]
-
-/* Handle cases that may overflow or underflow when computing the result that
- is scale*(1+TMP) without intermediate rounding. The bit representation of
- scale is in SBITS, however it has a computed exponent that may have
- overflown into the sign bit so that needs to be adjusted before using it as
- a double. (int32_t)KI is the k used in the argument reduction and exponent
- adjustment of scale, positive k here means the result may overflow and
- negative k means the result may underflow. */
-static inline double specialcase(double_t tmp, uint64_t sbits, uint64_t ki)
-{
- double_t scale, y;
-
- if ((ki & 0x80000000) == 0) {
- /* k > 0, the exponent of scale might have overflowed by <= 460. */
- sbits -= 1009ull << 52;
- scale = asdouble(sbits);
- y = 0x1p1009 * (scale + scale * tmp);
- return eval_as_double(y);
- }
- /* k < 0, need special care in the subnormal range. */
- sbits += 1022ull << 52;
- scale = asdouble(sbits);
- y = scale + scale * tmp;
- if (y < 1.0) {
- /* Round y to the right precision before scaling it into the subnormal
- range to avoid double rounding that can cause 0.5+E/2 ulp error where
- E is the worst-case ulp error outside the subnormal range. So this
- is only useful if the goal is better than 1 ulp worst-case error. */
- double_t hi, lo;
- lo = scale - y + scale * tmp;
- hi = 1.0 + y;
- lo = 1.0 - hi + y + lo;
- y = eval_as_double(hi + lo) - 1.0;
- /* Avoid -0.0 with downward rounding. */
- if (WANT_ROUNDING && y == 0.0)
- y = 0.0;
- /* The underflow exception needs to be signaled explicitly. */
- fp_force_eval(fp_barrier(0x1p-1022) * 0x1p-1022);
- }
- y = 0x1p-1022 * y;
- return eval_as_double(y);
-}
-
-/* Top 12 bits of a double (sign and exponent bits). */
-static inline uint32_t top12(double x)
-{
- return asuint64(x) >> 52;
-}
-
-double exp(double x)
-{
- uint32_t abstop;
- uint64_t ki, idx, top, sbits;
- double_t kd, z, r, r2, scale, tail, tmp;
-
- abstop = top12(x) & 0x7ff;
- if (predict_false(abstop - top12(0x1p-54) >= top12(512.0) - top12(0x1p-54))) {
- if (abstop - top12(0x1p-54) >= 0x80000000)
- /* Avoid spurious underflow for tiny x. */
- /* Note: 0 is common input. */
- return WANT_ROUNDING ? 1.0 + x : 1.0;
- if (abstop >= top12(1024.0)) {
- if (asuint64(x) == asuint64(-INFINITY))
- return 0.0;
- if (abstop >= top12(INFINITY))
- return 1.0 + x;
- if (asuint64(x) >> 63)
- return __math_uflow(0);
- else
- return __math_oflow(0);
- }
- /* Large x is special cased below. */
- abstop = 0;
- }
-
- /* exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)]. */
- /* x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N]. */
- z = InvLn2N * x;
-#if TOINT_INTRINSICS
- kd = roundtoint(z);
- ki = converttoint(z);
-#elif EXP_USE_TOINT_NARROW
- /* z - kd is in [-0.5-2^-16, 0.5] in all rounding modes. */
- kd = eval_as_double(z + Shift);
- ki = asuint64(kd) >> 16;
- kd = (double_t)(int32_t)ki;
-#else
- /* z - kd is in [-1, 1] in non-nearest rounding modes. */
- kd = eval_as_double(z + Shift);
- ki = asuint64(kd);
- kd -= Shift;
-#endif
- r = x + kd * NegLn2hiN + kd * NegLn2loN;
- /* 2^(k/N) ~= scale * (1 + tail). */
- idx = 2 * (ki % N);
- top = ki << (52 - EXP_TABLE_BITS);
- tail = asdouble(T[idx]);
- /* This is only a valid scale when -1023*N < k < 1024*N. */
- sbits = T[idx + 1] + top;
- /* exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1). */
- /* Evaluation is optimized assuming superscalar pipelined execution. */
- r2 = r * r;
- /* Without fma the worst case error is 0.25/N ulp larger. */
- /* Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp. */
- tmp = tail + r + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);
- if (predict_false(abstop == 0))
- return specialcase(tmp, sbits, ki);
- scale = asdouble(sbits);
- /* Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there
- is no spurious underflow here even without fma. */
- return eval_as_double(scale + scale * tmp);
-}
diff --git a/lib/libc/musl/src/math/exp2.c b/lib/libc/musl/src/math/exp2.c
@@ -1,121 +0,0 @@
-/*
- * Double-precision 2^x function.
- *
- * Copyright (c) 2018, Arm Limited.
- * SPDX-License-Identifier: MIT
- */
-
-#include <math.h>
-#include <stdint.h>
-#include "libm.h"
-#include "exp_data.h"
-
-#define N (1 << EXP_TABLE_BITS)
-#define Shift __exp_data.exp2_shift
-#define T __exp_data.tab
-#define C1 __exp_data.exp2_poly[0]
-#define C2 __exp_data.exp2_poly[1]
-#define C3 __exp_data.exp2_poly[2]
-#define C4 __exp_data.exp2_poly[3]
-#define C5 __exp_data.exp2_poly[4]
-
-/* Handle cases that may overflow or underflow when computing the result that
- is scale*(1+TMP) without intermediate rounding. The bit representation of
- scale is in SBITS, however it has a computed exponent that may have
- overflown into the sign bit so that needs to be adjusted before using it as
- a double. (int32_t)KI is the k used in the argument reduction and exponent
- adjustment of scale, positive k here means the result may overflow and
- negative k means the result may underflow. */
-static inline double specialcase(double_t tmp, uint64_t sbits, uint64_t ki)
-{
- double_t scale, y;
-
- if ((ki & 0x80000000) == 0) {
- /* k > 0, the exponent of scale might have overflowed by 1. */
- sbits -= 1ull << 52;
- scale = asdouble(sbits);
- y = 2 * (scale + scale * tmp);
- return eval_as_double(y);
- }
- /* k < 0, need special care in the subnormal range. */
- sbits += 1022ull << 52;
- scale = asdouble(sbits);
- y = scale + scale * tmp;
- if (y < 1.0) {
- /* Round y to the right precision before scaling it into the subnormal
- range to avoid double rounding that can cause 0.5+E/2 ulp error where
- E is the worst-case ulp error outside the subnormal range. So this
- is only useful if the goal is better than 1 ulp worst-case error. */
- double_t hi, lo;
- lo = scale - y + scale * tmp;
- hi = 1.0 + y;
- lo = 1.0 - hi + y + lo;
- y = eval_as_double(hi + lo) - 1.0;
- /* Avoid -0.0 with downward rounding. */
- if (WANT_ROUNDING && y == 0.0)
- y = 0.0;
- /* The underflow exception needs to be signaled explicitly. */
- fp_force_eval(fp_barrier(0x1p-1022) * 0x1p-1022);
- }
- y = 0x1p-1022 * y;
- return eval_as_double(y);
-}
-
-/* Top 12 bits of a double (sign and exponent bits). */
-static inline uint32_t top12(double x)
-{
- return asuint64(x) >> 52;
-}
-
-double exp2(double x)
-{
- uint32_t abstop;
- uint64_t ki, idx, top, sbits;
- double_t kd, r, r2, scale, tail, tmp;
-
- abstop = top12(x) & 0x7ff;
- if (predict_false(abstop - top12(0x1p-54) >= top12(512.0) - top12(0x1p-54))) {
- if (abstop - top12(0x1p-54) >= 0x80000000)
- /* Avoid spurious underflow for tiny x. */
- /* Note: 0 is common input. */
- return WANT_ROUNDING ? 1.0 + x : 1.0;
- if (abstop >= top12(1024.0)) {
- if (asuint64(x) == asuint64(-INFINITY))
- return 0.0;
- if (abstop >= top12(INFINITY))
- return 1.0 + x;
- if (!(asuint64(x) >> 63))
- return __math_oflow(0);
- else if (asuint64(x) >= asuint64(-1075.0))
- return __math_uflow(0);
- }
- if (2 * asuint64(x) > 2 * asuint64(928.0))
- /* Large x is special cased below. */
- abstop = 0;
- }
-
- /* exp2(x) = 2^(k/N) * 2^r, with 2^r in [2^(-1/2N),2^(1/2N)]. */
- /* x = k/N + r, with int k and r in [-1/2N, 1/2N]. */
- kd = eval_as_double(x + Shift);
- ki = asuint64(kd); /* k. */
- kd -= Shift; /* k/N for int k. */
- r = x - kd;
- /* 2^(k/N) ~= scale * (1 + tail). */
- idx = 2 * (ki % N);
- top = ki << (52 - EXP_TABLE_BITS);
- tail = asdouble(T[idx]);
- /* This is only a valid scale when -1023*N < k < 1024*N. */
- sbits = T[idx + 1] + top;
- /* exp2(x) = 2^(k/N) * 2^r ~= scale + scale * (tail + 2^r - 1). */
- /* Evaluation is optimized assuming superscalar pipelined execution. */
- r2 = r * r;
- /* Without fma the worst case error is 0.5/N ulp larger. */
- /* Worst case error is less than 0.5+0.86/N+(abs poly error * 2^53) ulp. */
- tmp = tail + r * C1 + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);
- if (predict_false(abstop == 0))
- return specialcase(tmp, sbits, ki);
- scale = asdouble(sbits);
- /* Note: tmp == 0 or |tmp| > 2^-65 and scale > 2^-928, so there
- is no spurious underflow here even without fma. */
- return eval_as_double(scale + scale * tmp);
-}
diff --git a/lib/libc/musl/src/math/exp2f.c b/lib/libc/musl/src/math/exp2f.c
@@ -1,69 +0,0 @@
-/*
- * Single-precision 2^x function.
- *
- * Copyright (c) 2017-2018, Arm Limited.
- * SPDX-License-Identifier: MIT
- */
-
-#include <math.h>
-#include <stdint.h>
-#include "libm.h"
-#include "exp2f_data.h"
-
-/*
-EXP2F_TABLE_BITS = 5
-EXP2F_POLY_ORDER = 3
-
-ULP error: 0.502 (nearest rounding.)
-Relative error: 1.69 * 2^-34 in [-1/64, 1/64] (before rounding.)
-Wrong count: 168353 (all nearest rounding wrong results with fma.)
-Non-nearest ULP error: 1 (rounded ULP error)
-*/
-
-#define N (1 << EXP2F_TABLE_BITS)
-#define T __exp2f_data.tab
-#define C __exp2f_data.poly
-#define SHIFT __exp2f_data.shift_scaled
-
-static inline uint32_t top12(float x)
-{
- return asuint(x) >> 20;
-}
-
-float exp2f(float x)
-{
- uint32_t abstop;
- uint64_t ki, t;
- double_t kd, xd, z, r, r2, y, s;
-
- xd = (double_t)x;
- abstop = top12(x) & 0x7ff;
- if (predict_false(abstop >= top12(128.0f))) {
- /* |x| >= 128 or x is nan. */
- if (asuint(x) == asuint(-INFINITY))
- return 0.0f;
- if (abstop >= top12(INFINITY))
- return x + x;
- if (x > 0.0f)
- return __math_oflowf(0);
- if (x <= -150.0f)
- return __math_uflowf(0);
- }
-
- /* x = k/N + r with r in [-1/(2N), 1/(2N)] and int k. */
- kd = eval_as_double(xd + SHIFT);
- ki = asuint64(kd);
- kd -= SHIFT; /* k/N for int k. */
- r = xd - kd;
-
- /* exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1) */
- t = T[ki % N];
- t += ki << (52 - EXP2F_TABLE_BITS);
- s = asdouble(t);
- z = C[0] * r + C[1];
- r2 = r * r;
- y = C[2] * r + 1;
- y = z * r2 + y;
- y = y * s;
- return eval_as_float(y);
-}
diff --git a/lib/libc/musl/src/math/expf.c b/lib/libc/musl/src/math/expf.c
@@ -1,80 +0,0 @@
-/*
- * Single-precision e^x function.
- *
- * Copyright (c) 2017-2018, Arm Limited.
- * SPDX-License-Identifier: MIT
- */
-
-#include <math.h>
-#include <stdint.h>
-#include "libm.h"
-#include "exp2f_data.h"
-
-/*
-EXP2F_TABLE_BITS = 5
-EXP2F_POLY_ORDER = 3
-
-ULP error: 0.502 (nearest rounding.)
-Relative error: 1.69 * 2^-34 in [-ln2/64, ln2/64] (before rounding.)
-Wrong count: 170635 (all nearest rounding wrong results with fma.)
-Non-nearest ULP error: 1 (rounded ULP error)
-*/
-
-#define N (1 << EXP2F_TABLE_BITS)
-#define InvLn2N __exp2f_data.invln2_scaled
-#define T __exp2f_data.tab
-#define C __exp2f_data.poly_scaled
-
-static inline uint32_t top12(float x)
-{
- return asuint(x) >> 20;
-}
-
-float expf(float x)
-{
- uint32_t abstop;
- uint64_t ki, t;
- double_t kd, xd, z, r, r2, y, s;
-
- xd = (double_t)x;
- abstop = top12(x) & 0x7ff;
- if (predict_false(abstop >= top12(88.0f))) {
- /* |x| >= 88 or x is nan. */
- if (asuint(x) == asuint(-INFINITY))
- return 0.0f;
- if (abstop >= top12(INFINITY))
- return x + x;
- if (x > 0x1.62e42ep6f) /* x > log(0x1p128) ~= 88.72 */
- return __math_oflowf(0);
- if (x < -0x1.9fe368p6f) /* x < log(0x1p-150) ~= -103.97 */
- return __math_uflowf(0);
- }
-
- /* x*N/Ln2 = k + r with r in [-1/2, 1/2] and int k. */
- z = InvLn2N * xd;
-
- /* Round and convert z to int, the result is in [-150*N, 128*N] and
- ideally ties-to-even rule is used, otherwise the magnitude of r
- can be bigger which gives larger approximation error. */
-#if TOINT_INTRINSICS
- kd = roundtoint(z);
- ki = converttoint(z);
-#else
-# define SHIFT __exp2f_data.shift
- kd = eval_as_double(z + SHIFT);
- ki = asuint64(kd);
- kd -= SHIFT;
-#endif
- r = z - kd;
-
- /* exp(x) = 2^(k/N) * 2^(r/N) ~= s * (C0*r^3 + C1*r^2 + C2*r + 1) */
- t = T[ki % N];
- t += ki << (52 - EXP2F_TABLE_BITS);
- s = asdouble(t);
- z = C[0] * r + C[1];
- r2 = r * r;
- y = C[2] * r + 1;
- y = z * r2 + y;
- y = y * s;
- return eval_as_float(y);
-}
diff --git a/lib/libc/musl/src/math/fmod.c b/lib/libc/musl/src/math/fmod.c
@@ -1,68 +0,0 @@
-#include <math.h>
-#include <stdint.h>
-
-double fmod(double x, double y)
-{
- union {double f; uint64_t i;} ux = {x}, uy = {y};
- int ex = ux.i>>52 & 0x7ff;
- int ey = uy.i>>52 & 0x7ff;
- int sx = ux.i>>63;
- uint64_t i;
-
- /* in the followings uxi should be ux.i, but then gcc wrongly adds */
- /* float load/store to inner loops ruining performance and code size */
- uint64_t uxi = ux.i;
-
- if (uy.i<<1 == 0 || isnan(y) || ex == 0x7ff)
- return (x*y)/(x*y);
- if (uxi<<1 <= uy.i<<1) {
- if (uxi<<1 == uy.i<<1)
- return 0*x;
- return x;
- }
-
- /* normalize x and y */
- if (!ex) {
- for (i = uxi<<12; i>>63 == 0; ex--, i <<= 1);
- uxi <<= -ex + 1;
- } else {
- uxi &= -1ULL >> 12;
- uxi |= 1ULL << 52;
- }
- if (!ey) {
- for (i = uy.i<<12; i>>63 == 0; ey--, i <<= 1);
- uy.i <<= -ey + 1;
- } else {
- uy.i &= -1ULL >> 12;
- uy.i |= 1ULL << 52;
- }
-
- /* x mod y */
- for (; ex > ey; ex--) {
- i = uxi - uy.i;
- if (i >> 63 == 0) {
- if (i == 0)
- return 0*x;
- uxi = i;
- }
- uxi <<= 1;
- }
- i = uxi - uy.i;
- if (i >> 63 == 0) {
- if (i == 0)
- return 0*x;
- uxi = i;
- }
- for (; uxi>>52 == 0; uxi <<= 1, ex--);
-
- /* scale result */
- if (ex > 0) {
- uxi -= 1ULL << 52;
- uxi |= (uint64_t)ex << 52;
- } else {
- uxi >>= -ex + 1;
- }
- uxi |= (uint64_t)sx << 63;
- ux.i = uxi;
- return ux.f;
-}
diff --git a/lib/libc/musl/src/math/fmodf.c b/lib/libc/musl/src/math/fmodf.c
@@ -1,65 +0,0 @@
-#include <math.h>
-#include <stdint.h>
-
-float fmodf(float x, float y)
-{
- union {float f; uint32_t i;} ux = {x}, uy = {y};
- int ex = ux.i>>23 & 0xff;
- int ey = uy.i>>23 & 0xff;
- uint32_t sx = ux.i & 0x80000000;
- uint32_t i;
- uint32_t uxi = ux.i;
-
- if (uy.i<<1 == 0 || isnan(y) || ex == 0xff)
- return (x*y)/(x*y);
- if (uxi<<1 <= uy.i<<1) {
- if (uxi<<1 == uy.i<<1)
- return 0*x;
- return x;
- }
-
- /* normalize x and y */
- if (!ex) {
- for (i = uxi<<9; i>>31 == 0; ex--, i <<= 1);
- uxi <<= -ex + 1;
- } else {
- uxi &= -1U >> 9;
- uxi |= 1U << 23;
- }
- if (!ey) {
- for (i = uy.i<<9; i>>31 == 0; ey--, i <<= 1);
- uy.i <<= -ey + 1;
- } else {
- uy.i &= -1U >> 9;
- uy.i |= 1U << 23;
- }
-
- /* x mod y */
- for (; ex > ey; ex--) {
- i = uxi - uy.i;
- if (i >> 31 == 0) {
- if (i == 0)
- return 0*x;
- uxi = i;
- }
- uxi <<= 1;
- }
- i = uxi - uy.i;
- if (i >> 31 == 0) {
- if (i == 0)
- return 0*x;
- uxi = i;
- }
- for (; uxi>>23 == 0; uxi <<= 1, ex--);
-
- /* scale result up */
- if (ex > 0) {
- uxi -= 1U << 23;
- uxi |= (uint32_t)ex << 23;
- } else {
- uxi >>= -ex + 1;
- }
- uxi |= sx;
- ux.i = uxi;
- return ux.f;
-}
diff --git a/lib/libc/musl/src/math/fmodl.c b/lib/libc/musl/src/math/fmodl.c
@@ -1,105 +0,0 @@
-#include "libm.h"
-
-#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
-long double fmodl(long double x, long double y)
-{
- return fmod(x, y);
-}
-#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
-long double fmodl(long double x, long double y)
-{
- union ldshape ux = {x}, uy = {y};
- int ex = ux.i.se & 0x7fff;
- int ey = uy.i.se & 0x7fff;
- int sx = ux.i.se & 0x8000;
-
- if (y == 0 || isnan(y) || ex == 0x7fff)
- return (x*y)/(x*y);
- ux.i.se = ex;
- uy.i.se = ey;
- if (ux.f <= uy.f) {
- if (ux.f == uy.f)
- return 0*x;
- return x;
- }
-
- /* normalize x and y */
- if (!ex) {
- ux.f *= 0x1p120f;
- ex = ux.i.se - 120;
- }
- if (!ey) {
- uy.f *= 0x1p120f;
- ey = uy.i.se - 120;
- }
-
- /* x mod y */
-#if LDBL_MANT_DIG == 64
- uint64_t i, mx, my;
- mx = ux.i.m;
- my = uy.i.m;
- for (; ex > ey; ex--) {
- i = mx - my;
- if (mx >= my) {
- if (i == 0)
- return 0*x;
- mx = 2*i;
- } else if (2*mx < mx) {
- mx = 2*mx - my;
- } else {
- mx = 2*mx;
- }
- }
- i = mx - my;
- if (mx >= my) {
- if (i == 0)
- return 0*x;
- mx = i;
- }
- for (; mx >> 63 == 0; mx *= 2, ex--);
- ux.i.m = mx;
-#elif LDBL_MANT_DIG == 113
- uint64_t hi, lo, xhi, xlo, yhi, ylo;
- xhi = (ux.i2.hi & -1ULL>>16) | 1ULL<<48;
- yhi = (uy.i2.hi & -1ULL>>16) | 1ULL<<48;
- xlo = ux.i2.lo;
- ylo = uy.i2.lo;
- for (; ex > ey; ex--) {
- hi = xhi - yhi;
- lo = xlo - ylo;
- if (xlo < ylo)
- hi -= 1;
- if (hi >> 63 == 0) {
- if ((hi|lo) == 0)
- return 0*x;
- xhi = 2*hi + (lo>>63);
- xlo = 2*lo;
- } else {
- xhi = 2*xhi + (xlo>>63);
- xlo = 2*xlo;
- }
- }
- hi = xhi - yhi;
- lo = xlo - ylo;
- if (xlo < ylo)
- hi -= 1;
- if (hi >> 63 == 0) {
- if ((hi|lo) == 0)
- return 0*x;
- xhi = hi;
- xlo = lo;
- }
- for (; xhi >> 48 == 0; xhi = 2*xhi + (xlo>>63), xlo = 2*xlo, ex--);
- ux.i2.hi = xhi;
- ux.i2.lo = xlo;
-#endif
-
- /* scale result */
- if (ex <= 0) {
- ux.i.se = (ex+120)|sx;
- ux.f *= 0x1p-120f;
- } else
- ux.i.se = ex|sx;
- return ux.f;
-}
-#endif
diff --git a/lib/libc/musl/src/math/log.c b/lib/libc/musl/src/math/log.c
@@ -1,112 +0,0 @@
-/*
- * Double-precision log(x) function.
- *
- * Copyright (c) 2018, Arm Limited.
- * SPDX-License-Identifier: MIT
- */
-
-#include <math.h>
-#include <stdint.h>
-#include "libm.h"
-#include "log_data.h"
-
-#define T __log_data.tab
-#define T2 __log_data.tab2
-#define B __log_data.poly1
-#define A __log_data.poly
-#define Ln2hi __log_data.ln2hi
-#define Ln2lo __log_data.ln2lo
-#define N (1 << LOG_TABLE_BITS)
-#define OFF 0x3fe6000000000000
-
-/* Top 16 bits of a double. */
-static inline uint32_t top16(double x)
-{
- return asuint64(x) >> 48;
-}
-
-double log(double x)
-{
- double_t w, z, r, r2, r3, y, invc, logc, kd, hi, lo;
- uint64_t ix, iz, tmp;
- uint32_t top;
- int k, i;
-
- ix = asuint64(x);
- top = top16(x);
-#define LO asuint64(1.0 - 0x1p-4)
-#define HI asuint64(1.0 + 0x1.09p-4)
- if (predict_false(ix - LO < HI - LO)) {
- /* Handle close to 1.0 inputs separately. */
- /* Fix sign of zero with downward rounding when x==1. */
- if (WANT_ROUNDING && predict_false(ix == asuint64(1.0)))
- return 0;
- r = x - 1.0;
- r2 = r * r;
- r3 = r * r2;
- y = r3 *
- (B[1] + r * B[2] + r2 * B[3] +
- r3 * (B[4] + r * B[5] + r2 * B[6] +
- r3 * (B[7] + r * B[8] + r2 * B[9] + r3 * B[10])));
- /* Worst-case error is around 0.507 ULP. */
- w = r * 0x1p27;
- double_t rhi = r + w - w;
- double_t rlo = r - rhi;
- w = rhi * rhi * B[0]; /* B[0] == -0.5. */
- hi = r + w;
- lo = r - hi + w;
- lo += B[0] * rlo * (rhi + r);
- y += lo;
- y += hi;
- return eval_as_double(y);
- }
- if (predict_false(top - 0x0010 >= 0x7ff0 - 0x0010)) {
- /* x < 0x1p-1022 or inf or nan. */
- if (ix * 2 == 0)
- return __math_divzero(1);
- if (ix == asuint64(INFINITY)) /* log(inf) == inf. */
- return x;
- if ((top & 0x8000) || (top & 0x7ff0) == 0x7ff0)
- return __math_invalid(x);
- /* x is subnormal, normalize it. */
- ix = asuint64(x * 0x1p52);
- ix -= 52ULL << 52;
- }
-
- /* x = 2^k z; where z is in range [OFF,2*OFF) and exact.
- The range is split into N subintervals.
- The ith subinterval contains z and c is near its center. */
- tmp = ix - OFF;
- i = (tmp >> (52 - LOG_TABLE_BITS)) % N;
- k = (int64_t)tmp >> 52; /* arithmetic shift */
- iz = ix - (tmp & 0xfffULL << 52);
- invc = T[i].invc;
- logc = T[i].logc;
- z = asdouble(iz);
-
- /* log(x) = log1p(z/c-1) + log(c) + k*Ln2. */
- /* r ~= z/c - 1, |r| < 1/(2*N). */
-#if __FP_FAST_FMA
- /* rounding error: 0x1p-55/N. */
- r = __builtin_fma(z, invc, -1.0);
-#else
- /* rounding error: 0x1p-55/N + 0x1p-66. */
- r = (z - T2[i].chi - T2[i].clo) * invc;
-#endif
- kd = (double_t)k;
-
- /* hi + lo = r + log(c) + k*Ln2. */
- w = kd * Ln2hi + logc;
- hi = w + r;
- lo = w - hi + r + kd * Ln2lo;
-
- /* log(x) = lo + (log1p(r) - r) + hi. */
- r2 = r * r; /* rounding error: 0x1p-54/N^2. */
- /* Worst case error if |y| > 0x1p-5:
- 0.5 + 4.13/N + abs-poly-error*2^57 ULP (+ 0.002 ULP without fma)
- Worst case error if |y| > 0x1p-4:
- 0.5 + 2.06/N + abs-poly-error*2^56 ULP (+ 0.001 ULP without fma). */
- y = lo + r2 * A[0] +
- r * r2 * (A[1] + r * A[2] + r2 * (A[3] + r * A[4])) + hi;
- return eval_as_double(y);
-}
diff --git a/lib/libc/musl/src/math/log10.c b/lib/libc/musl/src/math/log10.c
@@ -1,101 +0,0 @@
-/* origin: FreeBSD /usr/src/lib/msun/src/e_log10.c */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunSoft, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
- * is preserved.
- * ====================================================
- */
-/*
- * Return the base 10 logarithm of x. See log.c for most comments.
- *
- * Reduce x to 2^k (1+f) and calculate r = log(1+f) - f + f*f/2
- * as in log.c, then combine and scale in extra precision:
- * log10(x) = (f - f*f/2 + r)/log(10) + k*log10(2)
- */
-
-#include <math.h>
-#include <stdint.h>
-
-static const double
-ivln10hi = 4.34294481878168880939e-01, /* 0x3fdbcb7b, 0x15200000 */
-ivln10lo = 2.50829467116452752298e-11, /* 0x3dbb9438, 0xca9aadd5 */
-log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
-log10_2lo = 3.69423907715893078616e-13, /* 0x3D59FEF3, 0x11F12B36 */
-Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
-Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
-Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
-Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
-Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
-Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
-Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
-
-double log10(double x)
-{
- union {double f; uint64_t i;} u = {x};
- double_t hfsq,f,s,z,R,w,t1,t2,dk,y,hi,lo,val_hi,val_lo;
- uint32_t hx;
- int k;
-
- hx = u.i>>32;
- k = 0;
- if (hx < 0x00100000 || hx>>31) {
- if (u.i<<1 == 0)
- return -1/(x*x); /* log(+-0)=-inf */
- if (hx>>31)
- return (x-x)/0.0; /* log(-#) = NaN */
- /* subnormal number, scale x up */
- k -= 54;
- x *= 0x1p54;
- u.f = x;
- hx = u.i>>32;
- } else if (hx >= 0x7ff00000) {
- return x;
- } else if (hx == 0x3ff00000 && u.i<<32 == 0)
- return 0;
-
- /* reduce x into [sqrt(2)/2, sqrt(2)] */
- hx += 0x3ff00000 - 0x3fe6a09e;
- k += (int)(hx>>20) - 0x3ff;
- hx = (hx&0x000fffff) + 0x3fe6a09e;
- u.i = (uint64_t)hx<<32 | (u.i&0xffffffff);
- x = u.f;
-
- f = x - 1.0;
- hfsq = 0.5*f*f;
- s = f/(2.0+f);
- z = s*s;
- w = z*z;
- t1 = w*(Lg2+w*(Lg4+w*Lg6));
- t2 = z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));
- R = t2 + t1;
-
- /* See log2.c for details. */
- /* hi+lo = f - hfsq + s*(hfsq+R) ~ log(1+f) */
- hi = f - hfsq;
- u.f = hi;
- u.i &= (uint64_t)-1<<32;
- hi = u.f;
- lo = f - hi - hfsq + s*(hfsq+R);
-
- /* val_hi+val_lo ~ log10(1+f) + k*log10(2) */
- val_hi = hi*ivln10hi;
- dk = k;
- y = dk*log10_2hi;
- val_lo = dk*log10_2lo + (lo+hi)*ivln10lo + lo*ivln10hi;
-
- /*
- * Extra precision in for adding y is not strictly needed
- * since there is no very large cancellation near x = sqrt(2) or
- * x = 1/sqrt(2), but we do it anyway since it costs little on CPUs
- * with some parallelism and it reduces the error for many args.
- */
- w = y + val_hi;
- val_lo += (y - w) + val_hi;
- val_hi = w;
-
- return val_lo + val_hi;
-}
diff --git a/lib/libc/musl/src/math/log10f.c b/lib/libc/musl/src/math/log10f.c
@@ -1,77 +0,0 @@
-/* origin: FreeBSD /usr/src/lib/msun/src/e_log10f.c */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunPro, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
- * is preserved.
- * ====================================================
- */
-/*
- * See comments in log10.c.
- */
-
-#include <math.h>
-#include <stdint.h>
-
-static const float
-ivln10hi = 4.3432617188e-01, /* 0x3ede6000 */
-ivln10lo = -3.1689971365e-05, /* 0xb804ead9 */
-log10_2hi = 3.0102920532e-01, /* 0x3e9a2080 */
-log10_2lo = 7.9034151668e-07, /* 0x355427db */
-/* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */
-Lg1 = 0xaaaaaa.0p-24, /* 0.66666662693 */
-Lg2 = 0xccce13.0p-25, /* 0.40000972152 */
-Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */
-Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */
-
-float log10f(float x)
-{
- union {float f; uint32_t i;} u = {x};
- float_t hfsq,f,s,z,R,w,t1,t2,dk,hi,lo;
- uint32_t ix;
- int k;
-
- ix = u.i;
- k = 0;
- if (ix < 0x00800000 || ix>>31) { /* x < 2**-126 */
- if (ix<<1 == 0)
- return -1/(x*x); /* log(+-0)=-inf */
- if (ix>>31)
- return (x-x)/0.0f; /* log(-#) = NaN */
- /* subnormal number, scale up x */
- k -= 25;
- x *= 0x1p25f;
- u.f = x;
- ix = u.i;
- } else if (ix >= 0x7f800000) {
- return x;
- } else if (ix == 0x3f800000)
- return 0;
-
- /* reduce x into [sqrt(2)/2, sqrt(2)] */
- ix += 0x3f800000 - 0x3f3504f3;
- k += (int)(ix>>23) - 0x7f;
- ix = (ix&0x007fffff) + 0x3f3504f3;
- u.i = ix;
- x = u.f;
-
- f = x - 1.0f;
- s = f/(2.0f + f);
- z = s*s;
- w = z*z;
- t1= w*(Lg2+w*Lg4);
- t2= z*(Lg1+w*Lg3);
- R = t2 + t1;
- hfsq = 0.5f*f*f;
-
- hi = f - hfsq;
- u.f = hi;
- u.i &= 0xfffff000;
- hi = u.f;
- lo = f - hi - hfsq + s*(hfsq+R);
- dk = k;
- return dk*log10_2lo + (lo+hi)*ivln10lo + lo*ivln10hi + hi*ivln10hi + dk*log10_2hi;
-}
diff --git a/lib/libc/musl/src/math/log2.c b/lib/libc/musl/src/math/log2.c
@@ -1,122 +0,0 @@
-/*
- * Double-precision log2(x) function.
- *
- * Copyright (c) 2018, Arm Limited.
- * SPDX-License-Identifier: MIT
- */
-
-#include <math.h>
-#include <stdint.h>
-#include "libm.h"
-#include "log2_data.h"
-
-#define T __log2_data.tab
-#define T2 __log2_data.tab2
-#define B __log2_data.poly1
-#define A __log2_data.poly
-#define InvLn2hi __log2_data.invln2hi
-#define InvLn2lo __log2_data.invln2lo
-#define N (1 << LOG2_TABLE_BITS)
-#define OFF 0x3fe6000000000000
-
-/* Top 16 bits of a double. */
-static inline uint32_t top16(double x)
-{
- return asuint64(x) >> 48;
-}
-
-double log2(double x)
-{
- double_t z, r, r2, r4, y, invc, logc, kd, hi, lo, t1, t2, t3, p;
- uint64_t ix, iz, tmp;
- uint32_t top;
- int k, i;
-
- ix = asuint64(x);
- top = top16(x);
-#define LO asuint64(1.0 - 0x1.5b51p-5)
-#define HI asuint64(1.0 + 0x1.6ab2p-5)
- if (predict_false(ix - LO < HI - LO)) {
- /* Handle close to 1.0 inputs separately. */
- /* Fix sign of zero with downward rounding when x==1. */
- if (WANT_ROUNDING && predict_false(ix == asuint64(1.0)))
- return 0;
- r = x - 1.0;
-#if __FP_FAST_FMA
- hi = r * InvLn2hi;
- lo = r * InvLn2lo + __builtin_fma(r, InvLn2hi, -hi);
-#else
- double_t rhi, rlo;
- rhi = asdouble(asuint64(r) & -1ULL << 32);
- rlo = r - rhi;
- hi = rhi * InvLn2hi;
- lo = rlo * InvLn2hi + r * InvLn2lo;
-#endif
- r2 = r * r; /* rounding error: 0x1p-62. */
- r4 = r2 * r2;
- /* Worst-case error is less than 0.54 ULP (0.55 ULP without fma). */
- p = r2 * (B[0] + r * B[1]);
- y = hi + p;
- lo += hi - y + p;
- lo += r4 * (B[2] + r * B[3] + r2 * (B[4] + r * B[5]) +
- r4 * (B[6] + r * B[7] + r2 * (B[8] + r * B[9])));
- y += lo;
- return eval_as_double(y);
- }
- if (predict_false(top - 0x0010 >= 0x7ff0 - 0x0010)) {
- /* x < 0x1p-1022 or inf or nan. */
- if (ix * 2 == 0)
- return __math_divzero(1);
- if (ix == asuint64(INFINITY)) /* log(inf) == inf. */
- return x;
- if ((top & 0x8000) || (top & 0x7ff0) == 0x7ff0)
- return __math_invalid(x);
- /* x is subnormal, normalize it. */
- ix = asuint64(x * 0x1p52);
- ix -= 52ULL << 52;
- }
-
- /* x = 2^k z; where z is in range [OFF,2*OFF) and exact.
- The range is split into N subintervals.
- The ith subinterval contains z and c is near its center. */
- tmp = ix - OFF;
- i = (tmp >> (52 - LOG2_TABLE_BITS)) % N;
- k = (int64_t)tmp >> 52; /* arithmetic shift */
- iz = ix - (tmp & 0xfffULL << 52);
- invc = T[i].invc;
- logc = T[i].logc;
- z = asdouble(iz);
- kd = (double_t)k;
-
- /* log2(x) = log2(z/c) + log2(c) + k. */
- /* r ~= z/c - 1, |r| < 1/(2*N). */
-#if __FP_FAST_FMA
- /* rounding error: 0x1p-55/N. */
- r = __builtin_fma(z, invc, -1.0);
- t1 = r * InvLn2hi;
- t2 = r * InvLn2lo + __builtin_fma(r, InvLn2hi, -t1);
-#else
- double_t rhi, rlo;
- /* rounding error: 0x1p-55/N + 0x1p-65. */
- r = (z - T2[i].chi - T2[i].clo) * invc;
- rhi = asdouble(asuint64(r) & -1ULL << 32);
- rlo = r - rhi;
- t1 = rhi * InvLn2hi;
- t2 = rlo * InvLn2hi + r * InvLn2lo;
-#endif
-
- /* hi + lo = r/ln2 + log2(c) + k. */
- t3 = kd + logc;
- hi = t3 + t1;
- lo = t3 - hi + t1 + t2;
-
- /* log2(r+1) = r/ln2 + r^2*poly(r). */
- /* Evaluation is optimized assuming superscalar pipelined execution. */
- r2 = r * r; /* rounding error: 0x1p-54/N^2. */
- r4 = r2 * r2;
- /* Worst-case error if |y| > 0x1p-4: 0.547 ULP (0.550 ULP without fma).
- ~ 0.5 + 2/N/ln2 + abs-poly-error*0x1p56 ULP (+ 0.003 ULP without fma). */
- p = A[0] + r * A[1] + r2 * (A[2] + r * A[3]) + r4 * (A[4] + r * A[5]);
- y = lo + r2 * p + hi;
- return eval_as_double(y);
-}
diff --git a/lib/libc/musl/src/math/log2f.c b/lib/libc/musl/src/math/log2f.c
@@ -1,72 +0,0 @@
-/*
- * Single-precision log2 function.
- *
- * Copyright (c) 2017-2018, Arm Limited.
- * SPDX-License-Identifier: MIT
- */
-
-#include <math.h>
-#include <stdint.h>
-#include "libm.h"
-#include "log2f_data.h"
-
-/*
-LOG2F_TABLE_BITS = 4
-LOG2F_POLY_ORDER = 4
-
-ULP error: 0.752 (nearest rounding.)
-Relative error: 1.9 * 2^-26 (before rounding.)
-*/
-
-#define N (1 << LOG2F_TABLE_BITS)
-#define T __log2f_data.tab
-#define A __log2f_data.poly
-#define OFF 0x3f330000
-
-float log2f(float x)
-{
- double_t z, r, r2, p, y, y0, invc, logc;
- uint32_t ix, iz, top, tmp;
- int k, i;
-
- ix = asuint(x);
- /* Fix sign of zero with downward rounding when x==1. */
- if (WANT_ROUNDING && predict_false(ix == 0x3f800000))
- return 0;
- if (predict_false(ix - 0x00800000 >= 0x7f800000 - 0x00800000)) {
- /* x < 0x1p-126 or inf or nan. */
- if (ix * 2 == 0)
- return __math_divzerof(1);
- if (ix == 0x7f800000) /* log2(inf) == inf. */
- return x;
- if ((ix & 0x80000000) || ix * 2 >= 0xff000000)
- return __math_invalidf(x);
- /* x is subnormal, normalize it. */
- ix = asuint(x * 0x1p23f);
- ix -= 23 << 23;
- }
-
- /* x = 2^k z; where z is in range [OFF,2*OFF] and exact.
- The range is split into N subintervals.
- The ith subinterval contains z and c is near its center. */
- tmp = ix - OFF;
- i = (tmp >> (23 - LOG2F_TABLE_BITS)) % N;
- top = tmp & 0xff800000;
- iz = ix - top;
- k = (int32_t)tmp >> 23; /* arithmetic shift */
- invc = T[i].invc;
- logc = T[i].logc;
- z = (double_t)asfloat(iz);
-
- /* log2(x) = log1p(z/c-1)/ln2 + log2(c) + k */
- r = z * invc - 1;
- y0 = logc + (double_t)k;
-
- /* Pipelined polynomial evaluation to approximate log1p(r)/ln2. */
- r2 = r * r;
- y = A[1] * r + A[2];
- y = A[0] * r2 + y;
- p = A[3] * r + y0;
- y = y * r2 + p;
- return eval_as_float(y);
-}
diff --git a/lib/libc/musl/src/math/logf.c b/lib/libc/musl/src/math/logf.c
@@ -1,71 +0,0 @@
-/*
- * Single-precision log function.
- *
- * Copyright (c) 2017-2018, Arm Limited.
- * SPDX-License-Identifier: MIT
- */
-
-#include <math.h>
-#include <stdint.h>
-#include "libm.h"
-#include "logf_data.h"
-
-/*
-LOGF_TABLE_BITS = 4
-LOGF_POLY_ORDER = 4
-
-ULP error: 0.818 (nearest rounding.)
-Relative error: 1.957 * 2^-26 (before rounding.)
-*/
-
-#define T __logf_data.tab
-#define A __logf_data.poly
-#define Ln2 __logf_data.ln2
-#define N (1 << LOGF_TABLE_BITS)
-#define OFF 0x3f330000
-
-float logf(float x)
-{
- double_t z, r, r2, y, y0, invc, logc;
- uint32_t ix, iz, tmp;
- int k, i;
-
- ix = asuint(x);
- /* Fix sign of zero with downward rounding when x==1. */
- if (WANT_ROUNDING && predict_false(ix == 0x3f800000))
- return 0;
- if (predict_false(ix - 0x00800000 >= 0x7f800000 - 0x00800000)) {
- /* x < 0x1p-126 or inf or nan. */
- if (ix * 2 == 0)
- return __math_divzerof(1);
- if (ix == 0x7f800000) /* log(inf) == inf. */
- return x;
- if ((ix & 0x80000000) || ix * 2 >= 0xff000000)
- return __math_invalidf(x);
- /* x is subnormal, normalize it. */
- ix = asuint(x * 0x1p23f);
- ix -= 23 << 23;
- }
-
- /* x = 2^k z; where z is in range [OFF,2*OFF] and exact.
- The range is split into N subintervals.
- The ith subinterval contains z and c is near its center. */
- tmp = ix - OFF;
- i = (tmp >> (23 - LOGF_TABLE_BITS)) % N;
- k = (int32_t)tmp >> 23; /* arithmetic shift */
- iz = ix - (tmp & 0xff800000);
- invc = T[i].invc;
- logc = T[i].logc;
- z = (double_t)asfloat(iz);
-
- /* log(x) = log1p(z/c-1) + log(c) + k*Ln2 */
- r = z * invc - 1;
- y0 = logc + (double_t)k * Ln2;
-
- /* Pipelined polynomial evaluation to approximate log1p(r). */
- r2 = r * r;
- y = A[1] * r + A[2];
- y = A[0] * r2 + y;
- y = y * r2 + (y0 + r);
- return eval_as_float(y);
-}
diff --git a/lib/libc/musl/src/string/bcmp.c b/lib/libc/musl/src/string/bcmp.c
@@ -1,8 +0,0 @@
-#define _BSD_SOURCE
-#include <string.h>
-#include <strings.h>
-
-int bcmp(const void *s1, const void *s2, size_t n)
-{
- return memcmp(s1, s2, n);
-}
diff --git a/src/libs/mingw.zig b/src/libs/mingw.zig
@@ -998,9 +998,6 @@ const mingw32_x86_src = [_][]const u8{
const mingw32_x86_32_src = [_][]const u8{
// ucrtbase
"math" ++ path.sep_str ++ "coshf.c",
- "math" ++ path.sep_str ++ "expf.c",
- "math" ++ path.sep_str ++ "log10f.c",
- "math" ++ path.sep_str ++ "logf.c",
"math" ++ path.sep_str ++ "modff.c",
"math" ++ path.sep_str ++ "powf.c",
"math" ++ path.sep_str ++ "sinhf.c",
diff --git a/src/libs/musl.zig b/src/libs/musl.zig
@@ -900,13 +900,9 @@ const src_files = [_][]const u8{
"musl/src/math/exp10.c",
"musl/src/math/exp10f.c",
"musl/src/math/exp10l.c",
- "musl/src/math/exp2.c",
- "musl/src/math/exp2f.c",
"musl/src/math/exp2f_data.c",
"musl/src/math/exp2l.c",
- "musl/src/math/exp.c",
"musl/src/math/exp_data.c",
- "musl/src/math/expf.c",
"musl/src/math/expl.c",
"musl/src/math/expm1.c",
"musl/src/math/expm1f.c",
@@ -927,9 +923,6 @@ const src_files = [_][]const u8{
"musl/src/math/fmin.c",
"musl/src/math/fminf.c",
"musl/src/math/fminl.c",
- "musl/src/math/fmod.c",
- "musl/src/math/fmodf.c",
- "musl/src/math/fmodl.c",
"musl/src/math/__fpclassify.c",
"musl/src/math/__fpclassifyf.c",
"musl/src/math/__fpclassifyl.c",
@@ -1024,23 +1017,17 @@ const src_files = [_][]const u8{
"musl/src/math/llround.c",
"musl/src/math/llroundf.c",
"musl/src/math/llroundl.c",
- "musl/src/math/log10.c",
- "musl/src/math/log10f.c",
"musl/src/math/log10l.c",
"musl/src/math/log1p.c",
"musl/src/math/log1pf.c",
"musl/src/math/log1pl.c",
- "musl/src/math/log2.c",
"musl/src/math/log2_data.c",
- "musl/src/math/log2f.c",
"musl/src/math/log2f_data.c",
"musl/src/math/log2l.c",
"musl/src/math/logb.c",
"musl/src/math/logbf.c",
"musl/src/math/logbl.c",
- "musl/src/math/log.c",
"musl/src/math/log_data.c",
- "musl/src/math/logf.c",
"musl/src/math/logf_data.c",
"musl/src/math/logl.c",
"musl/src/math/lrint.c",
@@ -1752,7 +1739,6 @@ const src_files = [_][]const u8{
"musl/src/stdlib/strtol.c",
"musl/src/stdlib/wcstod.c",
"musl/src/stdlib/wcstol.c",
- "musl/src/string/bcmp.c",
"musl/src/string/bcopy.c",
"musl/src/string/explicit_bzero.c",
"musl/src/string/index.c",
diff --git a/src/libs/wasi_libc.zig b/src/libs/wasi_libc.zig
@@ -739,13 +739,9 @@ const libc_top_half_src_files = [_][]const u8{
"musl/src/math/exp10.c",
"musl/src/math/exp10f.c",
"musl/src/math/exp10l.c",
- "musl/src/math/exp2.c",
- "musl/src/math/exp2f.c",
"musl/src/math/exp2f_data.c",
"musl/src/math/exp2l.c",
- "musl/src/math/exp.c",
"musl/src/math/exp_data.c",
- "musl/src/math/expf.c",
"musl/src/math/expl.c",
"musl/src/math/expm1.c",
"musl/src/math/expm1f.c",
@@ -759,9 +755,6 @@ const libc_top_half_src_files = [_][]const u8{
"musl/src/math/fmaf.c",
"musl/src/math/fmaxl.c",
"musl/src/math/fminl.c",
- "musl/src/math/fmod.c",
- "musl/src/math/fmodf.c",
- "musl/src/math/fmodl.c",
"musl/src/math/frexp.c",
"musl/src/math/frexpf.c",
"musl/src/math/frexpl.c",
@@ -792,23 +785,17 @@ const libc_top_half_src_files = [_][]const u8{
"musl/src/math/llround.c",
"musl/src/math/llroundf.c",
"musl/src/math/llroundl.c",
- "musl/src/math/log10.c",
- "musl/src/math/log10f.c",
"musl/src/math/log10l.c",
"musl/src/math/log1p.c",
"musl/src/math/log1pf.c",
"musl/src/math/log1pl.c",
- "musl/src/math/log2.c",
"musl/src/math/log2_data.c",
- "musl/src/math/log2f.c",
"musl/src/math/log2f_data.c",
"musl/src/math/log2l.c",
"musl/src/math/logb.c",
"musl/src/math/logbf.c",
"musl/src/math/logbl.c",
- "musl/src/math/log.c",
"musl/src/math/log_data.c",
- "musl/src/math/logf.c",
"musl/src/math/logf_data.c",
"musl/src/math/logl.c",
"musl/src/math/lrint.c",
@@ -1031,7 +1018,6 @@ const libc_top_half_src_files = [_][]const u8{
"musl/src/stdlib/qsort.c",
"musl/src/stdlib/qsort_nr.c",
"musl/src/stdlib/strtol.c",
- "musl/src/string/bcmp.c",
"musl/src/string/bcopy.c",
"musl/src/string/explicit_bzero.c",
"musl/src/string/index.c",