diff --git a/lib/compiler_rt/cos.zig b/lib/compiler_rt/cos.zig index 582de530f5186b9d435081ad117ed6cf2d7e7f40..aa9282625fba5a3b95aa0b55cb7fc23a6df090ed 100644 --- a/lib/compiler_rt/cos.zig +++ b/lib/compiler_rt/cos.zig @@ -20,11 +20,11 @@ const rem_pio2l = @import("rem_pio2l.zig").rem_pio2l; const ld = @import("long_double.zig"); comptime { - symbol(&__cosh, "__cosh"); + symbol(&cosh, "__cosh"); symbol(&cosl, "__cosl"); symbol(&cosf, "cosf"); symbol(&cos, "cos"); - symbol(&__cosx, "__cosx"); + symbol(&cosx, "__cosx"); if (compiler_rt.want_ppc_abi) { symbol(&cosq, "cosf128"); } @@ -32,7 +32,7 @@ comptime { symbol(&cosl, "cosl"); } -pub fn __cosh(a: f16) callconv(.c) f16 { +pub fn cosh(a: f16) callconv(.c) f16 { // TODO: more efficient implementation return @floatCast(cosf(a)); } @@ -54,27 +54,27 @@ pub fn cosf(x: f32) callconv(.c) f32 { if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120); return 1.0; } - return trig.__cosdf(x); + return trig.cosdf(x); } if (ix <= 0x407b53d1) { // |x| ~<= 5*pi/4 if (ix > 0x4016cbe3) { // |x| ~> 3*pi/4 - return -trig.__cosdf(if (sign) x + c2pio2 else x - c2pio2); + return -trig.cosdf(if (sign) x + c2pio2 else x - c2pio2); } else { if (sign) { - return trig.__sindf(x + c1pio2); + return trig.sindf(x + c1pio2); } else { - return trig.__sindf(c1pio2 - x); + return trig.sindf(c1pio2 - x); } } } if (ix <= 0x40e231d5) { // |x| ~<= 9*pi/4 if (ix > 0x40afeddf) { // |x| ~> 7*pi/4 - return trig.__cosdf(if (sign) x + c4pio2 else x - c4pio2); + return trig.cosdf(if (sign) x + c4pio2 else x - c4pio2); } else { if (sign) { - return trig.__sindf(-x - c3pio2); + return trig.sindf(-x - c3pio2); } else { - return trig.__sindf(x - c3pio2); + return trig.sindf(x - c3pio2); } } } @@ -87,10 +87,10 @@ pub fn cosf(x: f32) callconv(.c) f32 { var y: f64 = undefined; const n = rem_pio2f(x, &y); return switch (n & 3) { - 0 => trig.__cosdf(y), - 1 => trig.__sindf(-y), - 2 => -trig.__cosdf(y), - else => trig.__sindf(y), + 0 => trig.cosdf(y), + 1 => trig.sindf(-y), + 2 => -trig.cosdf(y), + else => trig.sindf(y), }; } @@ -105,7 +105,7 @@ pub fn cos(x: f64) callconv(.c) f64 { if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120); return 1.0; } - return trig.__cos(x, 0); + return trig.cos(x, 0); } // cos(Inf or NaN) is NaN @@ -116,10 +116,10 @@ pub fn cos(x: f64) callconv(.c) f64 { var y: [2]f64 = undefined; const n = rem_pio2(x, &y); return switch (n & 3) { - 0 => trig.__cos(y[0], y[1]), - 1 => -trig.__sin(y[0], y[1], 1), - 2 => -trig.__cos(y[0], y[1]), - else => trig.__sin(y[0], y[1], 1), + 0 => trig.cos(y[0], y[1]), + 1 => -trig.sin(y[0], y[1], 1), + 2 => -trig.cos(y[0], y[1]), + else => trig.sin(y[0], y[1], 1), }; } @@ -134,20 +134,20 @@ fn coslGeneric(comptime T: type, x: T) T { // raise inexact if x!=0 return 1.0 + x; } - return trig.__cosl(T, x, 0.0); + return trig.cosl(T, x, 0.0); } var y: [2]T = undefined; const n = rem_pio2l(T, x, &y); return switch (n & 3) { - 0 => trig.__cosl(T, y[0], y[1]), - 1 => -trig.__sinl(T, y[0], y[1], 1), - 2 => -trig.__cosl(T, y[0], y[1]), - else => trig.__sinl(T, y[0], y[1], 1), + 0 => trig.cosl(T, y[0], y[1]), + 1 => -trig.sinl(T, y[0], y[1], 1), + 2 => -trig.cosl(T, y[0], y[1]), + else => trig.sinl(T, y[0], y[1], 1), }; } -pub fn __cosx(x: f80) callconv(.c) f80 { +pub fn cosx(x: f80) callconv(.c) f80 { return coslGeneric(f80, x); } @@ -157,10 +157,10 @@ pub fn cosq(x: f128) callconv(.c) f128 { pub fn cosl(x: c_longdouble) callconv(.c) c_longdouble { switch (@typeInfo(c_longdouble).float.bits) { - 16 => return __cosh(x), + 16 => return cosh(x), 32 => return cosf(x), 64 => return cos(x), - 80 => return __cosx(x), + 80 => return cosx(x), 128 => return cosq(x), else => @compileError("unreachable"), } @@ -170,7 +170,7 @@ fn testCosSpecial(comptime T: type) !void { const f = switch (T) { f32 => cosf, f64 => cos, - f80 => __cosx, + f80 => cosx, f128 => cosq, else => @compileError("unimplemented"), }; @@ -214,13 +214,13 @@ test "cos64.special" { test "cos80.normal" { const epsilon = math.floatEps(f80); - try expectApproxEqAbs(@as(f80, 1.0), __cosx(0.0), epsilon); - try expectApproxEqAbs(@as(f80, 0.98006657784124163112419651674816888), __cosx(0.2), epsilon); - try expectApproxEqAbs(@as(f80, 0.62762309833608037003563995939286067), __cosx(0.8923), epsilon); - try expectApproxEqAbs(@as(f80, 0.070737201667702910088189851434268747), __cosx(1.5), epsilon); - try expectApproxEqAbs(@as(f80, 0.070737201667702910088189851434268747), __cosx(-1.5), epsilon); - try expectApproxEqAbs(@as(f80, 0.9691317730707771246), __cosx(37.45), epsilon); - try expectApproxEqAbs(@as(f80, 0.4008006809354834001), __cosx(89.123), epsilon); + try expectApproxEqAbs(@as(f80, 1.0), cosx(0.0), epsilon); + try expectApproxEqAbs(@as(f80, 0.98006657784124163112419651674816888), cosx(0.2), epsilon); + try expectApproxEqAbs(@as(f80, 0.62762309833608037003563995939286067), cosx(0.8923), epsilon); + try expectApproxEqAbs(@as(f80, 0.070737201667702910088189851434268747), cosx(1.5), epsilon); + try expectApproxEqAbs(@as(f80, 0.070737201667702910088189851434268747), cosx(-1.5), epsilon); + try expectApproxEqAbs(@as(f80, 0.9691317730707771246), cosx(37.45), epsilon); + try expectApproxEqAbs(@as(f80, 0.4008006809354834001), cosx(89.123), epsilon); } test "cos80.special" { diff --git a/lib/compiler_rt/sin.zig b/lib/compiler_rt/sin.zig index 0cff43997e06e31606cd0be4ffb66d3cb36203a2..84f970cff5432a672715597c8a60bed9fd5cd46d 100644 --- a/lib/compiler_rt/sin.zig +++ b/lib/compiler_rt/sin.zig @@ -20,11 +20,11 @@ const rem_pio2l = @import("rem_pio2l.zig").rem_pio2l; const ld = @import("long_double.zig"); comptime { - symbol(&__sinh, "__sinh"); + symbol(&sinh, "__sinh"); symbol(&sinl, "__sinl"); symbol(&sinf, "sinf"); symbol(&sin, "sin"); - symbol(&__sinx, "__sinx"); + symbol(&sinx, "__sinx"); if (compiler_rt.want_ppc_abi) { symbol(&sinq, "sinf128"); } @@ -32,7 +32,7 @@ comptime { symbol(&sinl, "sinl"); } -pub fn __sinh(x: f16) callconv(.c) f16 { +pub fn sinh(x: f16) callconv(.c) f16 { // TODO: more efficient implementation return @floatCast(sinf(x)); } @@ -60,27 +60,27 @@ pub fn sinf(x: f32) callconv(.c) f32 { } return x; } - return trig.__sindf(x); + return trig.sindf(x); } if (ix <= 0x407b53d1) { // |x| ~<= 5*pi/4 if (ix <= 0x4016cbe3) { // |x| ~<= 3pi/4 if (sign) { - return -trig.__cosdf(x + s1pio2); + return -trig.cosdf(x + s1pio2); } else { - return trig.__cosdf(x - s1pio2); + return trig.cosdf(x - s1pio2); } } - return trig.__sindf(if (sign) -(x + s2pio2) else -(x - s2pio2)); + return trig.sindf(if (sign) -(x + s2pio2) else -(x - s2pio2)); } if (ix <= 0x40e231d5) { // |x| ~<= 9*pi/4 if (ix <= 0x40afeddf) { // |x| ~<= 7*pi/4 if (sign) { - return trig.__cosdf(x + s3pio2); + return trig.cosdf(x + s3pio2); } else { - return -trig.__cosdf(x - s3pio2); + return -trig.cosdf(x - s3pio2); } } - return trig.__sindf(if (sign) x + s4pio2 else x - s4pio2); + return trig.sindf(if (sign) x + s4pio2 else x - s4pio2); } // sin(Inf or NaN) is NaN @@ -91,10 +91,10 @@ pub fn sinf(x: f32) callconv(.c) f32 { var y: f64 = undefined; const n = rem_pio2f(x, &y); return switch (n & 3) { - 0 => trig.__sindf(y), - 1 => trig.__cosdf(y), - 2 => trig.__sindf(-y), - else => -trig.__cosdf(y), + 0 => trig.sindf(y), + 1 => trig.cosdf(y), + 2 => trig.sindf(-y), + else => -trig.cosdf(y), }; } @@ -115,7 +115,7 @@ pub fn sin(x: f64) callconv(.c) f64 { } return x; } - return trig.__sin(x, 0.0, 0); + return trig.sin(x, 0.0, 0); } // sin(Inf or NaN) is NaN @@ -126,10 +126,10 @@ pub fn sin(x: f64) callconv(.c) f64 { var y: [2]f64 = undefined; const n = rem_pio2(x, &y); return switch (n & 3) { - 0 => trig.__sin(y[0], y[1], 1), - 1 => trig.__cos(y[0], y[1]), - 2 => -trig.__sin(y[0], y[1], 1), - else => -trig.__cos(y[0], y[1]), + 0 => trig.sin(y[0], y[1], 1), + 1 => trig.cos(y[0], y[1]), + 2 => -trig.sin(y[0], y[1], 1), + else => -trig.cos(y[0], y[1]), }; } @@ -147,20 +147,20 @@ fn sinlGeneric(comptime T: type, x: T) T { } return x; } - return trig.__sinl(T, x, 0.0, 0); + return trig.sinl(T, x, 0.0, 0); } var y: [2]T = undefined; const n = rem_pio2l(T, x, &y); return switch (n & 3) { - 0 => trig.__sinl(T, y[0], y[1], 1), - 1 => trig.__cosl(T, y[0], y[1]), - 2 => -trig.__sinl(T, y[0], y[1], 1), - else => -trig.__cosl(T, y[0], y[1]), + 0 => trig.sinl(T, y[0], y[1], 1), + 1 => trig.cosl(T, y[0], y[1]), + 2 => -trig.sinl(T, y[0], y[1], 1), + else => -trig.cosl(T, y[0], y[1]), }; } -pub fn __sinx(x: f80) callconv(.c) f80 { +pub fn sinx(x: f80) callconv(.c) f80 { return sinlGeneric(f80, x); } @@ -170,10 +170,10 @@ pub fn sinq(x: f128) callconv(.c) f128 { pub fn sinl(x: c_longdouble) callconv(.c) c_longdouble { switch (@typeInfo(c_longdouble).float.bits) { - 16 => return __sinh(x), + 16 => return sinh(x), 32 => return sinf(x), 64 => return sin(x), - 80 => return __sinx(x), + 80 => return sinx(x), 128 => return sinq(x), else => @compileError("unreachable"), } @@ -183,7 +183,7 @@ fn testSinSpecial(comptime T: type) !void { const f = switch (T) { f32 => sinf, f64 => sin, - f80 => __sinx, + f80 => sinx, f128 => sinq, else => @compileError("unimplemented"), }; @@ -227,13 +227,13 @@ test "sin64.special" { test "sin80.normal" { const epsilon = math.floatEps(f80); - try expectApproxEqAbs(@as(f80, 0.0), __sinx(0.0), epsilon); - try expectApproxEqAbs(@as(f80, 0.19866933079506121545941262711838975), __sinx(0.2), epsilon); - try expectApproxEqAbs(@as(f80, 0.77851733855773487830689285621486050), __sinx(0.8923), epsilon); - try expectApproxEqAbs(@as(f80, 0.99749498660405443094172337114148732), __sinx(1.5), epsilon); - try expectApproxEqAbs(@as(f80, -0.99749498660405443094172337114148732), __sinx(-1.5), epsilon); - try expectApproxEqAbs(@as(f80, -0.24654331551411356504), __sinx(37.45), epsilon); - try expectApproxEqAbs(@as(f80, 0.91616527666226951006), __sinx(89.123), epsilon); + try expectApproxEqAbs(@as(f80, 0.0), sinx(0.0), epsilon); + try expectApproxEqAbs(@as(f80, 0.19866933079506121545941262711838975), sinx(0.2), epsilon); + try expectApproxEqAbs(@as(f80, 0.77851733855773487830689285621486050), sinx(0.8923), epsilon); + try expectApproxEqAbs(@as(f80, 0.99749498660405443094172337114148732), sinx(1.5), epsilon); + try expectApproxEqAbs(@as(f80, -0.99749498660405443094172337114148732), sinx(-1.5), epsilon); + try expectApproxEqAbs(@as(f80, -0.24654331551411356504), sinx(37.45), epsilon); + try expectApproxEqAbs(@as(f80, 0.91616527666226951006), sinx(89.123), epsilon); } test "sin80.special" { diff --git a/lib/compiler_rt/sincos.zig b/lib/compiler_rt/sincos.zig index 1616cc5556459503d5ac6fd9eeab045a9ba52c07..3f67627405dc3f3a8b2bd5b789eec15a253cb91a 100644 --- a/lib/compiler_rt/sincos.zig +++ b/lib/compiler_rt/sincos.zig @@ -14,10 +14,10 @@ const compiler_rt = @import("../compiler_rt.zig"); const symbol = compiler_rt.symbol; comptime { - symbol(&__sincosh, "__sincosh"); + symbol(&sincosh, "__sincosh"); symbol(&sincosf, "sincosf"); symbol(&sincos, "sincos"); - symbol(&__sincosx, "__sincosx"); + symbol(&sincosx, "__sincosx"); if (compiler_rt.want_ppc_abi) { symbol(&sincosq, "sincosf128"); } @@ -25,7 +25,7 @@ comptime { symbol(&sincosl, "sincosl"); } -pub fn __sincosh(x: f16, r_sin: *f16, r_cos: *f16) callconv(.c) void { +pub fn sincosh(x: f16, r_sin: *f16, r_cos: *f16) callconv(.c) void { // TODO: more efficient implementation var big_sin: f32 = undefined; var big_cos: f32 = undefined; @@ -60,8 +60,8 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.c) void { r_cos.* = 1.0; return; } - r_sin.* = trig.__sindf(x); - r_cos.* = trig.__cosdf(x); + r_sin.* = trig.sindf(x); + r_cos.* = trig.cosdf(x); return; } @@ -70,17 +70,17 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.c) void { // |x| ~<= 3pi/4 if (ix <= 0x4016cbe3) { if (sign) { - r_sin.* = -trig.__cosdf(x + sc1pio2); - r_cos.* = trig.__sindf(x + sc1pio2); + r_sin.* = -trig.cosdf(x + sc1pio2); + r_cos.* = trig.sindf(x + sc1pio2); } else { - r_sin.* = trig.__cosdf(sc1pio2 - x); - r_cos.* = trig.__sindf(sc1pio2 - x); + r_sin.* = trig.cosdf(sc1pio2 - x); + r_cos.* = trig.sindf(sc1pio2 - x); } return; } // -sin(x+c) is not correct if x+c could be 0: -0 vs +0 - r_sin.* = -trig.__sindf(if (sign) x + sc2pio2 else x - sc2pio2); - r_cos.* = -trig.__cosdf(if (sign) x + sc2pio2 else x - sc2pio2); + r_sin.* = -trig.sindf(if (sign) x + sc2pio2 else x - sc2pio2); + r_cos.* = -trig.cosdf(if (sign) x + sc2pio2 else x - sc2pio2); return; } @@ -89,16 +89,16 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.c) void { // |x| ~<= 7*pi/4 if (ix <= 0x40afeddf) { if (sign) { - r_sin.* = trig.__cosdf(x + sc3pio2); - r_cos.* = -trig.__sindf(x + sc3pio2); + r_sin.* = trig.cosdf(x + sc3pio2); + r_cos.* = -trig.sindf(x + sc3pio2); } else { - r_sin.* = -trig.__cosdf(x - sc3pio2); - r_cos.* = trig.__sindf(x - sc3pio2); + r_sin.* = -trig.cosdf(x - sc3pio2); + r_cos.* = trig.sindf(x - sc3pio2); } return; } - r_sin.* = trig.__sindf(if (sign) x + sc4pio2 else x - sc4pio2); - r_cos.* = trig.__cosdf(if (sign) x + sc4pio2 else x - sc4pio2); + r_sin.* = trig.sindf(if (sign) x + sc4pio2 else x - sc4pio2); + r_cos.* = trig.cosdf(if (sign) x + sc4pio2 else x - sc4pio2); return; } @@ -113,8 +113,8 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.c) void { // general argument reduction needed var y: f64 = undefined; const n = rem_pio2f(x, &y); - const s = trig.__sindf(y); - const c = trig.__cosdf(y); + const s = trig.sindf(y); + const c = trig.cosdf(y); switch (n & 3) { 0 => { r_sin.* = s; @@ -154,8 +154,8 @@ pub fn sincos(x: f64, r_sin: *f64, r_cos: *f64) callconv(.c) void { r_cos.* = 1.0; return; } - r_sin.* = trig.__sin(x, 0.0, 0); - r_cos.* = trig.__cos(x, 0.0); + r_sin.* = trig.sin(x, 0.0, 0); + r_cos.* = trig.cos(x, 0.0); return; } @@ -170,8 +170,8 @@ pub fn sincos(x: f64, r_sin: *f64, r_cos: *f64) callconv(.c) void { // argument reduction needed var y: [2]f64 = undefined; const n = rem_pio2(x, &y); - const s = trig.__sin(y[0], y[1], 1); - const c = trig.__cos(y[0], y[1]); + const s = trig.sin(y[0], y[1], 1); + const c = trig.cos(y[0], y[1]); switch (n & 3) { 0 => { r_sin.* = s; @@ -216,15 +216,15 @@ fn sincoslGeneric(comptime T: type, x: T, r_sin: *T, r_cos: *T) void { r_cos.* = 1.0 + x; return; } - r_sin.* = trig.__sinl(T, x, 0.0, 0); - r_cos.* = trig.__cosl(T, x, 0.0); + r_sin.* = trig.sinl(T, x, 0.0, 0); + r_cos.* = trig.cosl(T, x, 0.0); return; } var y: [2]T = undefined; const n = rem_pio2l(T, x, &y); - const s = trig.__sinl(T, y[0], y[1], 1); - const c = trig.__cosl(T, y[0], y[1]); + const s = trig.sinl(T, y[0], y[1], 1); + const c = trig.cosl(T, y[0], y[1]); switch (n & 3) { 0 => { r_sin.* = s; @@ -245,7 +245,7 @@ fn sincoslGeneric(comptime T: type, x: T, r_sin: *T, r_cos: *T) void { } } -pub fn __sincosx(x: f80, r_sin: *f80, r_cos: *f80) callconv(.c) void { +pub fn sincosx(x: f80, r_sin: *f80, r_cos: *f80) callconv(.c) void { return sincoslGeneric(f80, x, r_sin, r_cos); } @@ -255,10 +255,10 @@ pub fn sincosq(x: f128, r_sin: *f128, r_cos: *f128) callconv(.c) void { pub fn sincosl(x: c_longdouble, r_sin: *c_longdouble, r_cos: *c_longdouble) callconv(.c) void { switch (@typeInfo(c_longdouble).float.bits) { - 16 => return __sincosh(x, r_sin, r_cos), + 16 => return sincosh(x, r_sin, r_cos), 32 => return sincosf(x, r_sin, r_cos), 64 => return sincos(x, r_sin, r_cos), - 80 => return __sincosx(x, r_sin, r_cos), + 80 => return sincosx(x, r_sin, r_cos), 128 => return sincosq(x, r_sin, r_cos), else => @compileError("unreachable"), } @@ -268,7 +268,7 @@ fn testSincosSpecial(comptime T: type) !void { const f = switch (T) { f32 => sincosf, f64 => sincos, - f80 => __sincosx, + f80 => sincosx, f128 => sincosq, else => @compileError("unimplemented"), }; @@ -378,31 +378,31 @@ test "sincos80.normal" { var s: f80 = undefined; var c: f80 = undefined; - __sincosx(0.0, &s, &c); + sincosx(0.0, &s, &c); try expectApproxEqAbs(@as(f80, 0.0), s, epsilon); try expectApproxEqAbs(@as(f80, 1.0), c, epsilon); - __sincosx(0.2, &s, &c); + sincosx(0.2, &s, &c); try expectApproxEqAbs(@as(f80, 0.19866933079506121545941262711838975), s, epsilon); try expectApproxEqAbs(@as(f80, 0.98006657784124163112419651674816888), c, epsilon); - __sincosx(0.8923, &s, &c); + sincosx(0.8923, &s, &c); try expectApproxEqAbs(@as(f80, 0.77851733855773487830689285621486050), s, epsilon); try expectApproxEqAbs(@as(f80, 0.62762309833608037003563995939286067), c, epsilon); - __sincosx(1.5, &s, &c); + sincosx(1.5, &s, &c); try expectApproxEqAbs(@as(f80, 0.99749498660405443094172337114148732), s, epsilon); try expectApproxEqAbs(@as(f80, 0.070737201667702910088189851434268747), c, epsilon); - __sincosx(-1.5, &s, &c); + sincosx(-1.5, &s, &c); try expectApproxEqAbs(@as(f80, -0.99749498660405443094172337114148732), s, epsilon); try expectApproxEqAbs(@as(f80, 0.070737201667702910088189851434268747), c, epsilon); - __sincosx(37.45, &s, &c); + sincosx(37.45, &s, &c); try expectApproxEqAbs(@as(f80, -0.24654331551411356504), s, epsilon); try expectApproxEqAbs(@as(f80, 0.9691317730707771246), c, epsilon); - __sincosx(89.123, &s, &c); + sincosx(89.123, &s, &c); try expectApproxEqAbs(@as(f80, 0.91616527666226951006), s, epsilon); try expectApproxEqAbs(@as(f80, 0.4008006809354834001), c, epsilon); } diff --git a/lib/compiler_rt/tan.zig b/lib/compiler_rt/tan.zig index 1f925e3e8c6c6abac73d65d33f39ff2680377b03..5d5ba3196d52ee1f6f5161a8e0e36a587626cb30 100644 --- a/lib/compiler_rt/tan.zig +++ b/lib/compiler_rt/tan.zig @@ -24,10 +24,10 @@ const compiler_rt = @import("../compiler_rt.zig"); const symbol = @import("../compiler_rt.zig").symbol; comptime { - symbol(&__tanh, "__tanh"); + symbol(&tanh, "__tanh"); symbol(&tanf, "tanf"); symbol(&tan, "tan"); - symbol(&__tanx, "__tanx"); + symbol(&tanx, "__tanx"); if (compiler_rt.want_ppc_abi) { symbol(&tanq, "tanf128"); } @@ -35,7 +35,7 @@ comptime { symbol(&tanl, "tanl"); } -pub fn __tanh(x: f16) callconv(.c) f16 { +pub fn tanh(x: f16) callconv(.c) f16 { // TODO: more efficient implementation return @floatCast(tanf(x)); } @@ -63,20 +63,20 @@ pub fn tanf(x: f32) callconv(.c) f32 { } return x; } - return kernel.__tandf(x, false); + return kernel.tandf(x, false); } if (ix <= 0x407b53d1) { // |x| ~<= 5*pi/4 if (ix <= 0x4016cbe3) { // |x| ~<= 3pi/4 - return kernel.__tandf((if (sign) x + t1pio2 else x - t1pio2), true); + return kernel.tandf((if (sign) x + t1pio2 else x - t1pio2), true); } else { - return kernel.__tandf((if (sign) x + t2pio2 else x - t2pio2), false); + return kernel.tandf((if (sign) x + t2pio2 else x - t2pio2), false); } } if (ix <= 0x40e231d5) { // |x| ~<= 9*pi/4 if (ix <= 0x40afeddf) { // |x| ~<= 7*pi/4 - return kernel.__tandf((if (sign) x + t3pio2 else x - t3pio2), true); + return kernel.tandf((if (sign) x + t3pio2 else x - t3pio2), true); } else { - return kernel.__tandf((if (sign) x + t4pio2 else x - t4pio2), false); + return kernel.tandf((if (sign) x + t4pio2 else x - t4pio2), false); } } @@ -87,7 +87,7 @@ pub fn tanf(x: f32) callconv(.c) f32 { var y: f64 = undefined; const n = rem_pio2f(x, &y); - return kernel.__tandf(y, n & 1 != 0); + return kernel.tandf(y, n & 1 != 0); } pub fn tan(x: f64) callconv(.c) f64 { @@ -107,7 +107,7 @@ pub fn tan(x: f64) callconv(.c) f64 { } return x; } - return kernel.__tan(x, 0.0, false); + return kernel.tan(x, 0.0, false); } // tan(Inf or NaN) is NaN @@ -117,7 +117,7 @@ pub fn tan(x: f64) callconv(.c) f64 { var y: [2]f64 = undefined; const n = rem_pio2(x, &y); - return kernel.__tan(y[0], y[1], n & 1 != 0); + return kernel.tan(y[0], y[1], n & 1 != 0); } fn tanlGeneric(comptime T: type, x: T) T { @@ -137,15 +137,15 @@ fn tanlGeneric(comptime T: type, x: T) T { } return x; } - return kernel.__tanl(T, x, 0.0, 0); + return kernel.tanl(T, x, 0.0, 0); } var y: [2]T = undefined; const n = rem_pio2l(T, x, &y); - return kernel.__tanl(T, y[0], y[1], n & 1); + return kernel.tanl(T, y[0], y[1], n & 1); } -pub fn __tanx(x: f80) callconv(.c) f80 { +pub fn tanx(x: f80) callconv(.c) f80 { return tanlGeneric(f80, x); } @@ -155,10 +155,10 @@ pub fn tanq(x: f128) callconv(.c) f128 { pub fn tanl(x: c_longdouble) callconv(.c) c_longdouble { switch (@typeInfo(c_longdouble).float.bits) { - 16 => return __tanh(x), + 16 => return tanh(x), 32 => return tanf(x), 64 => return tan(x), - 80 => return __tanx(x), + 80 => return tanx(x), 128 => return tanq(x), else => @compileError("unreachable"), } @@ -184,7 +184,7 @@ fn testTanSpecial(comptime T: type) !void { const f = switch (T) { f32 => tanf, f64 => tan, - f80 => __tanx, + f80 => tanx, f128 => tanq, else => @compileError("unimplemented"), }; @@ -207,12 +207,12 @@ test "tan64.normal" { test "tan80.normal" { const epsilon = math.floatEps(f80); - try expectApproxEqAbs(@as(f80, 0.0), __tanx(0.0), epsilon); - try expectApproxEqAbs(@as(f80, 0.2027100355086724833213582716475345), __tanx(0.2), epsilon); - try expectApproxEqAbs(@as(f80, 1.2404217445497097995561220131857544), __tanx(0.8923), epsilon); - try expectApproxEqAbs(@as(f80, 14.10141994717171938764), __tanx(1.5), epsilon); - try expectApproxEqAbs(@as(f80, -0.25439607116885656232), __tanx(37.45), epsilon); - try expectApproxEqAbs(@as(f80, 2.2858376251355320963), __tanx(89.123), epsilon); + try expectApproxEqAbs(@as(f80, 0.0), tanx(0.0), epsilon); + try expectApproxEqAbs(@as(f80, 0.2027100355086724833213582716475345), tanx(0.2), epsilon); + try expectApproxEqAbs(@as(f80, 1.2404217445497097995561220131857544), tanx(0.8923), epsilon); + try expectApproxEqAbs(@as(f80, 14.10141994717171938764), tanx(1.5), epsilon); + try expectApproxEqAbs(@as(f80, -0.25439607116885656232), tanx(37.45), epsilon); + try expectApproxEqAbs(@as(f80, 2.2858376251355320963), tanx(89.123), epsilon); } test "tan128.normal" { diff --git a/lib/compiler_rt/trig.zig b/lib/compiler_rt/trig.zig index e68089baeab1b6a9ff4cb818e81db5ca7e14952a..7c106100ec3cecffb6c3b1a2c9423d84855c04b9 100644 --- a/lib/compiler_rt/trig.zig +++ b/lib/compiler_rt/trig.zig @@ -11,8 +11,9 @@ // https://git.musl-libc.org/cgit/musl/tree/src/math/__cosl.c // https://git.musl-libc.org/cgit/musl/tree/src/math/__tanl.c -/// pi divided by 4 -pub const pi_4 = 0.78539816339744830962; +const std = @import("std"); + +pub const pi_4 = std.math.pi / 4.0; /// kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164 /// Input x is assumed to be bounded by ~pi/4 in magnitude. @@ -49,7 +50,7 @@ pub const pi_4 = 0.78539816339744830962; /// expression for cos(). Retention happens in all cases tested /// under FreeBSD, so don't pessimize things by forcibly clipping /// any extra precision in w. -pub fn __cos(x: f64, y: f64) f64 { +pub fn cos(x: f64, y: f64) f64 { const C1 = 4.16666666666666019037e-02; // 0x3FA55555, 0x5555554C const C2 = -1.38888888888741095749e-03; // 0xBF56C16C, 0x16C15177 const C3 = 2.48015872894767294178e-05; // 0x3EFA01A0, 0x19CB1590 @@ -65,7 +66,7 @@ pub fn __cos(x: f64, y: f64) f64 { return w + (((1.0 - w) - hz) + (z * r - x * y)); } -pub fn __cosdf(x: f64) f32 { +pub fn cosdf(x: f64) f32 { // |cos(x) - c(x)| < 2**-34.1 (~[-5.37e-11, 5.295e-11]). const C0 = -0x1ffffffd0c5e81.0p-54; // -0.499999997251031003120 const C1 = 0x155553e1053a42.0p-57; // 0.0416666233237390631894 @@ -79,7 +80,7 @@ pub fn __cosdf(x: f64) f32 { return @floatCast(((1.0 + z * C0) + w * C1) + (w * z) * r); } -pub fn __cosl(comptime T: type, x: T, y: T) T { +pub fn cosl(comptime T: type, x: T, y: T) T { const impl = switch (T) { f80 => struct { const C1: T = 0.0416666666666666666136; @@ -115,7 +116,7 @@ pub fn __cosl(comptime T: type, x: T, y: T) T { z * (C7 + z * (C8 + z * (C9 + z * (C10 + z * C11)))))))))); } }, - else => @compileError("__cosl supports only f80 and f128, got: " ++ @typeName(T)), + else => @compileError("cosl supports only f80 and f128, got: " ++ @typeName(T)), }; const z = x * x; @@ -152,7 +153,7 @@ pub fn __cosl(comptime T: type, x: T, y: T) T { /// r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6)))) /// then 3 2 /// sin(x) = x + (S1*x + (x *(r-y/2)+y)) -pub fn __sin(x: f64, y: f64, iy: i32) f64 { +pub fn sin(x: f64, y: f64, iy: i32) f64 { const S1 = -1.66666666666666324348e-01; // 0xBFC55555, 0x55555549 const S2 = 8.33333333332248946124e-03; // 0x3F811111, 0x1110F8A6 const S3 = -1.98412698298579493134e-04; // 0xBF2A01A0, 0x19C161D5 @@ -171,7 +172,7 @@ pub fn __sin(x: f64, y: f64, iy: i32) f64 { } } -pub fn __sinl(comptime T: type, x: T, y: T, iy: i32) T { +pub fn sinl(comptime T: type, x: T, y: T, iy: i32) T { const impl = switch (T) { f80 => struct { const S1: T = -0.166666666666666666671; @@ -209,7 +210,7 @@ pub fn __sinl(comptime T: type, x: T, y: T, iy: i32) T { z * (S9 + z * (S10 + z * (S11 + z * S12))))))))); } }, - else => @compileError("__sinl supports only f80 and f128, got: " ++ @typeName(T)), + else => @compileError("sinl supports only f80 and f128, got: " ++ @typeName(T)), }; const z = x * x; @@ -223,7 +224,7 @@ pub fn __sinl(comptime T: type, x: T, y: T, iy: i32) T { return x - ((z * (0.5 * y - v * r) - y) - v * impl.S1); } -pub fn __sindf(x: f64) f32 { +pub fn sindf(x: f64) f32 { // |sin(x)/x - s(x)| < 2**-37.5 (~[-4.89e-12, 4.824e-12]). const S1 = -0x15555554cbac77.0p-55; // -0.166666666416265235595 const S2 = 0x111110896efbb2.0p-59; // 0.0083333293858894631756 @@ -270,7 +271,7 @@ pub fn __sindf(x: f64) f32 { /// 4. For x in [0.67434,pi/4], let y = pi/4 - x, then /// tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y)) /// = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y))) -pub fn __tan(x_: f64, y_: f64, odd: bool) f64 { +pub fn tan(x_: f64, y_: f64, odd: bool) f64 { var x = x_; var y = y_; @@ -343,7 +344,7 @@ pub fn __tan(x_: f64, y_: f64, odd: bool) f64 { return a0 + a * (1.0 + a0 * w0 + a0 * v); } -pub fn __tandf(x: f64, odd: bool) f32 { +pub fn tandf(x: f64, odd: bool) f32 { // |tan(x)/x - t(x)| < 2**-25.5 (~[-2e-08, 2e-08]). const T = [_]f64{ 0x15554d3418c99f.0p-54, // 0.333331395030791399758 @@ -376,7 +377,7 @@ pub fn __tandf(x: f64, odd: bool) f32 { return @floatCast(if (odd) -1.0 / r0 else r0); } -pub fn __tanl(comptime T: type, x_: T, y_: T, odd: i32) T { +pub fn tanl(comptime T: type, x_: T, y_: T, odd: i32) T { var x = x_; var y = y_; const impl = switch (T) { @@ -456,7 +457,7 @@ pub fn __tanl(comptime T: type, x_: T, y_: T, odd: i32) T { w * (T47 + w * (T51 + w * T55))))))))))); } }, - else => @compileError("__tanl supports only f80 and f128, got: " ++ @typeName(T)), + else => @compileError("tanl supports only f80 and f128, got: " ++ @typeName(T)), }; const big = @abs(x) >= 0.67434;