Deprecate math.doNotOptimizeAway, use mem.doNotOptimizeAway (#18011)

This commit is contained in:
John Benediktsson 2023-11-23 12:06:32 -08:00 committed by GitHub
parent 464ce8ac67
commit 54f4abae2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 59 additions and 45 deletions

View File

@ -8,6 +8,7 @@ const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const arch = builtin.cpu.arch; const arch = builtin.cpu.arch;
const math = std.math; const math = std.math;
const mem = std.mem;
const expect = std.testing.expect; const expect = std.testing.expect;
const common = @import("common.zig"); const common = @import("common.zig");
@ -47,14 +48,14 @@ pub fn ceilf(x: f32) callconv(.C) f32 {
if (u & m == 0) { if (u & m == 0) {
return x; return x;
} }
math.doNotOptimizeAway(x + 0x1.0p120); mem.doNotOptimizeAway(x + 0x1.0p120);
if (u >> 31 == 0) { if (u >> 31 == 0) {
u += m; u += m;
} }
u &= ~m; u &= ~m;
return @bitCast(u); return @bitCast(u);
} else { } else {
math.doNotOptimizeAway(x + 0x1.0p120); mem.doNotOptimizeAway(x + 0x1.0p120);
if (u >> 31 != 0) { if (u >> 31 != 0) {
return -0.0; return -0.0;
} else { } else {
@ -81,7 +82,7 @@ pub fn ceil(x: f64) callconv(.C) f64 {
} }
if (e <= 0x3FF - 1) { if (e <= 0x3FF - 1) {
math.doNotOptimizeAway(y); mem.doNotOptimizeAway(y);
if (u >> 63 != 0) { if (u >> 63 != 0) {
return -0.0; return -0.0;
} else { } else {
@ -115,7 +116,7 @@ pub fn ceilq(x: f128) callconv(.C) f128 {
} }
if (e <= 0x3FFF - 1) { if (e <= 0x3FFF - 1) {
math.doNotOptimizeAway(y); mem.doNotOptimizeAway(y);
if (u >> 127 != 0) { if (u >> 127 != 0) {
return -0.0; return -0.0;
} else { } else {

View File

@ -1,5 +1,6 @@
const std = @import("std"); const std = @import("std");
const math = std.math; const math = std.math;
const mem = std.mem;
const expect = std.testing.expect; const expect = std.testing.expect;
const common = @import("common.zig"); const common = @import("common.zig");
@ -40,7 +41,7 @@ pub fn cosf(x: f32) callconv(.C) f32 {
if (ix <= 0x3f490fda) { // |x| ~<= pi/4 if (ix <= 0x3f490fda) { // |x| ~<= pi/4
if (ix < 0x39800000) { // |x| < 2**-12 if (ix < 0x39800000) { // |x| < 2**-12
// raise inexact if x != 0 // raise inexact if x != 0
math.doNotOptimizeAway(x + 0x1p120); mem.doNotOptimizeAway(x + 0x1p120);
return 1.0; return 1.0;
} }
return trig.__cosdf(x); return trig.__cosdf(x);
@ -91,7 +92,7 @@ pub fn cos(x: f64) callconv(.C) f64 {
if (ix <= 0x3fe921fb) { if (ix <= 0x3fe921fb) {
if (ix < 0x3e46a09e) { // |x| < 2**-27 * sqrt(2) if (ix < 0x3e46a09e) { // |x| < 2**-27 * sqrt(2)
// raise inexact if x!=0 // raise inexact if x!=0
math.doNotOptimizeAway(x + 0x1p120); mem.doNotOptimizeAway(x + 0x1p120);
return 1.0; return 1.0;
} }
return trig.__cos(x, 0); return trig.__cos(x, 0);

View File

@ -8,6 +8,7 @@ const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const arch = builtin.cpu.arch; const arch = builtin.cpu.arch;
const math = std.math; const math = std.math;
const mem = std.mem;
const expect = std.testing.expect; const expect = std.testing.expect;
const common = @import("common.zig"); const common = @import("common.zig");
@ -58,7 +59,7 @@ pub fn expf(x_: f32) callconv(.C) f32 {
return x * 0x1.0p127; return x * 0x1.0p127;
} }
if (sign != 0) { if (sign != 0) {
math.doNotOptimizeAway(-0x1.0p-149 / x); // overflow mem.doNotOptimizeAway(-0x1.0p-149 / x); // overflow
// x <= -103.972084 // x <= -103.972084
if (hx >= 0x42CFF1B5) { if (hx >= 0x42CFF1B5) {
return 0; return 0;
@ -90,7 +91,7 @@ pub fn expf(x_: f32) callconv(.C) f32 {
hi = x; hi = x;
lo = 0; lo = 0;
} else { } else {
math.doNotOptimizeAway(0x1.0p127 + x); // inexact mem.doNotOptimizeAway(0x1.0p127 + x); // inexact
return 1 + x; return 1 + x;
} }
@ -141,7 +142,7 @@ pub fn exp(x_: f64) callconv(.C) f64 {
} }
if (x < -708.39641853226410622) { if (x < -708.39641853226410622) {
// underflow if x != -inf // underflow if x != -inf
// math.doNotOptimizeAway(@as(f32, -0x1.0p-149 / x)); // mem.doNotOptimizeAway(@as(f32, -0x1.0p-149 / x));
if (x < -745.13321910194110842) { if (x < -745.13321910194110842) {
return 0; return 0;
} }
@ -174,7 +175,7 @@ pub fn exp(x_: f64) callconv(.C) f64 {
lo = 0; lo = 0;
} else { } else {
// inexact if x != 0 // inexact if x != 0
// math.doNotOptimizeAway(0x1.0p1023 + x); // mem.doNotOptimizeAway(0x1.0p1023 + x);
return 1 + x; return 1 + x;
} }

View File

@ -8,6 +8,7 @@ const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const arch = builtin.cpu.arch; const arch = builtin.cpu.arch;
const math = std.math; const math = std.math;
const mem = std.mem;
const expect = std.testing.expect; const expect = std.testing.expect;
const common = @import("common.zig"); const common = @import("common.zig");
@ -54,7 +55,7 @@ pub fn exp2f(x: f32) callconv(.C) f32 {
// x < -126 // x < -126
if (u >= 0x80000000) { if (u >= 0x80000000) {
if (u >= 0xC3160000 or u & 0x000FFFF != 0) { if (u >= 0xC3160000 or u & 0x000FFFF != 0) {
math.doNotOptimizeAway(-0x1.0p-149 / x); mem.doNotOptimizeAway(-0x1.0p-149 / x);
} }
// x <= -150 // x <= -150
if (u >= 0x3160000) { if (u >= 0x3160000) {
@ -119,7 +120,7 @@ pub fn exp2(x: f64) callconv(.C) f64 {
if (ux >> 63 != 0) { if (ux >> 63 != 0) {
// underflow // underflow
if (x <= -1075 or x - 0x1.0p52 + 0x1.0p52 != x) { if (x <= -1075 or x - 0x1.0p52 + 0x1.0p52 != x) {
math.doNotOptimizeAway(@as(f32, @floatCast(-0x1.0p-149 / x))); mem.doNotOptimizeAway(@as(f32, @floatCast(-0x1.0p-149 / x)));
} }
if (x <= -1075) { if (x <= -1075) {
return 0; return 0;

View File

@ -7,6 +7,7 @@
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const math = std.math; const math = std.math;
const mem = std.mem;
const expect = std.testing.expect; const expect = std.testing.expect;
const arch = builtin.cpu.arch; const arch = builtin.cpu.arch;
const common = @import("common.zig"); const common = @import("common.zig");
@ -44,13 +45,13 @@ pub fn __floorh(x: f16) callconv(.C) f16 {
if (u & m == 0) { if (u & m == 0) {
return x; return x;
} }
math.doNotOptimizeAway(x + 0x1.0p120); mem.doNotOptimizeAway(x + 0x1.0p120);
if (u >> 15 != 0) { if (u >> 15 != 0) {
u += m; u += m;
} }
return @bitCast(u & ~m); return @bitCast(u & ~m);
} else { } else {
math.doNotOptimizeAway(x + 0x1.0p120); mem.doNotOptimizeAway(x + 0x1.0p120);
if (u >> 15 == 0) { if (u >> 15 == 0) {
return 0.0; return 0.0;
} else { } else {
@ -78,13 +79,13 @@ pub fn floorf(x: f32) callconv(.C) f32 {
if (u & m == 0) { if (u & m == 0) {
return x; return x;
} }
math.doNotOptimizeAway(x + 0x1.0p120); mem.doNotOptimizeAway(x + 0x1.0p120);
if (u >> 31 != 0) { if (u >> 31 != 0) {
u += m; u += m;
} }
return @bitCast(u & ~m); return @bitCast(u & ~m);
} else { } else {
math.doNotOptimizeAway(x + 0x1.0p120); mem.doNotOptimizeAway(x + 0x1.0p120);
if (u >> 31 == 0) { if (u >> 31 == 0) {
return 0.0; return 0.0;
} else { } else {
@ -111,7 +112,7 @@ pub fn floor(x: f64) callconv(.C) f64 {
} }
if (e <= 0x3FF - 1) { if (e <= 0x3FF - 1) {
math.doNotOptimizeAway(y); mem.doNotOptimizeAway(y);
if (u >> 63 != 0) { if (u >> 63 != 0) {
return -1.0; return -1.0;
} else { } else {
@ -145,7 +146,7 @@ pub fn floorq(x: f128) callconv(.C) f128 {
} }
if (e <= 0x3FFF - 1) { if (e <= 0x3FFF - 1) {
math.doNotOptimizeAway(y); mem.doNotOptimizeAway(y);
if (u >> 127 != 0) { if (u >> 127 != 0) {
return -1.0; return -1.0;
} else { } else {

View File

@ -7,6 +7,7 @@
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const math = std.math; const math = std.math;
const mem = std.mem;
const expect = std.testing.expect; const expect = std.testing.expect;
const arch = builtin.cpu.arch; const arch = builtin.cpu.arch;
const common = @import("common.zig"); const common = @import("common.zig");
@ -45,7 +46,7 @@ pub fn roundf(x_: f32) callconv(.C) f32 {
x = -x; x = -x;
} }
if (e < 0x7F - 1) { if (e < 0x7F - 1) {
math.doNotOptimizeAway(x + f32_toint); mem.doNotOptimizeAway(x + f32_toint);
return 0 * @as(f32, @bitCast(u)); return 0 * @as(f32, @bitCast(u));
} }
@ -80,7 +81,7 @@ pub fn round(x_: f64) callconv(.C) f64 {
x = -x; x = -x;
} }
if (e < 0x3ff - 1) { if (e < 0x3ff - 1) {
math.doNotOptimizeAway(x + f64_toint); mem.doNotOptimizeAway(x + f64_toint);
return 0 * @as(f64, @bitCast(u)); return 0 * @as(f64, @bitCast(u));
} }
@ -120,7 +121,7 @@ pub fn roundq(x_: f128) callconv(.C) f128 {
x = -x; x = -x;
} }
if (e < 0x3FFF - 1) { if (e < 0x3FFF - 1) {
math.doNotOptimizeAway(x + f128_toint); mem.doNotOptimizeAway(x + f128_toint);
return 0 * @as(f128, @bitCast(u)); return 0 * @as(f128, @bitCast(u));
} }

View File

@ -8,6 +8,7 @@ const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const arch = builtin.cpu.arch; const arch = builtin.cpu.arch;
const math = std.math; const math = std.math;
const mem = std.mem;
const expect = std.testing.expect; const expect = std.testing.expect;
const common = @import("common.zig"); const common = @import("common.zig");
@ -48,7 +49,7 @@ pub fn sinf(x: f32) callconv(.C) f32 {
if (ix <= 0x3f490fda) { // |x| ~<= pi/4 if (ix <= 0x3f490fda) { // |x| ~<= pi/4
if (ix < 0x39800000) { // |x| < 2**-12 if (ix < 0x39800000) { // |x| < 2**-12
// raise inexact if x!=0 and underflow if subnormal // raise inexact if x!=0 and underflow if subnormal
math.doNotOptimizeAway(if (ix < 0x00800000) x / 0x1p120 else x + 0x1p120); mem.doNotOptimizeAway(if (ix < 0x00800000) x / 0x1p120 else x + 0x1p120);
return x; return x;
} }
return trig.__sindf(x); return trig.__sindf(x);
@ -97,7 +98,7 @@ pub fn sin(x: f64) callconv(.C) f64 {
if (ix <= 0x3fe921fb) { if (ix <= 0x3fe921fb) {
if (ix < 0x3e500000) { // |x| < 2**-26 if (ix < 0x3e500000) { // |x| < 2**-26
// raise inexact if x != 0 and underflow if subnormal // raise inexact if x != 0 and underflow if subnormal
math.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120); mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
return x; return x;
} }
return trig.__sin(x, 0.0, 0); return trig.__sin(x, 0.0, 0);

View File

@ -2,6 +2,7 @@ const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const arch = builtin.cpu.arch; const arch = builtin.cpu.arch;
const math = std.math; const math = std.math;
const mem = std.mem;
const trig = @import("trig.zig"); const trig = @import("trig.zig");
const rem_pio2 = @import("rem_pio2.zig").rem_pio2; const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f; const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
@ -45,7 +46,7 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.C) void {
// |x| < 2**-12 // |x| < 2**-12
if (ix < 0x39800000) { if (ix < 0x39800000) {
// raise inexact if x!=0 and underflow if subnormal // raise inexact if x!=0 and underflow if subnormal
math.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120); mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
r_sin.* = x; r_sin.* = x;
r_cos.* = 1.0; r_cos.* = 1.0;
return; return;
@ -133,7 +134,7 @@ pub fn sincos(x: f64, r_sin: *f64, r_cos: *f64) callconv(.C) void {
// if |x| < 2**-27 * sqrt(2) // if |x| < 2**-27 * sqrt(2)
if (ix < 0x3e46a09e) { if (ix < 0x3e46a09e) {
// raise inexact if x != 0 and underflow if subnormal // raise inexact if x != 0 and underflow if subnormal
math.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120); mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
r_sin.* = x; r_sin.* = x;
r_cos.* = 1.0; r_cos.* = 1.0;
return; return;
@ -231,7 +232,7 @@ inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void {
if (se < 0x3fff - math.floatFractionalBits(F) - 1) { if (se < 0x3fff - math.floatFractionalBits(F) - 1) {
// raise underflow if subnormal // raise underflow if subnormal
if (se == 0) { if (se == 0) {
math.doNotOptimizeAway(x * 0x1p-120); mem.doNotOptimizeAway(x * 0x1p-120);
} }
r_sin.* = x; r_sin.* = x;
// raise inexact if x!=0 // raise inexact if x!=0

View File

@ -8,6 +8,7 @@
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const math = std.math; const math = std.math;
const mem = std.mem;
const expect = std.testing.expect; const expect = std.testing.expect;
const kernel = @import("trig.zig"); const kernel = @import("trig.zig");
@ -50,7 +51,7 @@ pub fn tanf(x: f32) callconv(.C) f32 {
if (ix <= 0x3f490fda) { // |x| ~<= pi/4 if (ix <= 0x3f490fda) { // |x| ~<= pi/4
if (ix < 0x39800000) { // |x| < 2**-12 if (ix < 0x39800000) { // |x| < 2**-12
// raise inexact if x!=0 and underflow if subnormal // raise inexact if x!=0 and underflow if subnormal
math.doNotOptimizeAway(if (ix < 0x00800000) x / 0x1p120 else x + 0x1p120); mem.doNotOptimizeAway(if (ix < 0x00800000) x / 0x1p120 else x + 0x1p120);
return x; return x;
} }
return kernel.__tandf(x, false); return kernel.__tandf(x, false);
@ -88,7 +89,7 @@ pub fn tan(x: f64) callconv(.C) f64 {
if (ix <= 0x3fe921fb) { if (ix <= 0x3fe921fb) {
if (ix < 0x3e400000) { // |x| < 2**-27 if (ix < 0x3e400000) { // |x| < 2**-27
// raise inexact if x!=0 and underflow if subnormal // raise inexact if x!=0 and underflow if subnormal
math.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120); mem.doNotOptimizeAway(if (ix < 0x00100000) x / 0x1p120 else x + 0x1p120);
return x; return x;
} }
return kernel.__tan(x, 0.0, false); return kernel.__tan(x, 0.0, false);

View File

@ -8,6 +8,7 @@ const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const arch = builtin.cpu.arch; const arch = builtin.cpu.arch;
const math = std.math; const math = std.math;
const mem = std.mem;
const expect = std.testing.expect; const expect = std.testing.expect;
const common = @import("common.zig"); const common = @import("common.zig");
@ -46,7 +47,7 @@ pub fn truncf(x: f32) callconv(.C) f32 {
if (u & m == 0) { if (u & m == 0) {
return x; return x;
} else { } else {
math.doNotOptimizeAway(x + 0x1p120); mem.doNotOptimizeAway(x + 0x1p120);
return @bitCast(u & ~m); return @bitCast(u & ~m);
} }
} }
@ -67,7 +68,7 @@ pub fn trunc(x: f64) callconv(.C) f64 {
if (u & m == 0) { if (u & m == 0) {
return x; return x;
} else { } else {
math.doNotOptimizeAway(x + 0x1p120); mem.doNotOptimizeAway(x + 0x1p120);
return @bitCast(u & ~m); return @bitCast(u & ~m);
} }
} }
@ -93,7 +94,7 @@ pub fn truncq(x: f128) callconv(.C) f128 {
if (u & m == 0) { if (u & m == 0) {
return x; return x;
} else { } else {
math.doNotOptimizeAway(x + 0x1p120); mem.doNotOptimizeAway(x + 0x1p120);
return @bitCast(u & ~m); return @bitCast(u & ~m);
} }
} }

View File

@ -186,9 +186,7 @@ test "approxEqAbs and approxEqRel" {
} }
} }
pub fn doNotOptimizeAway(val: anytype) void { pub const doNotOptimizeAway = @compileError("Deprecated: use `std.mem.doNotOptimizeAway` instead");
return mem.doNotOptimizeAway(val);
}
pub fn raiseInvalid() void { pub fn raiseInvalid() void {
// Raise INVALID fpu exception // Raise INVALID fpu exception

View File

@ -6,6 +6,7 @@
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const mem = std.mem;
const expect = std.testing.expect; const expect = std.testing.expect;
const maxInt = std.math.maxInt; const maxInt = std.math.maxInt;
@ -46,7 +47,7 @@ fn asinh32(x: f32) f32 {
} }
// |x| < 0x1p-12, inexact if x != 0 // |x| < 0x1p-12, inexact if x != 0
else { else {
math.doNotOptimizeAway(rx + 0x1.0p120); mem.doNotOptimizeAway(rx + 0x1.0p120);
} }
return if (s != 0) -rx else rx; return if (s != 0) -rx else rx;
@ -73,7 +74,7 @@ fn asinh64(x: f64) f64 {
} }
// |x| < 0x1p-12, inexact if x != 0 // |x| < 0x1p-12, inexact if x != 0
else { else {
math.doNotOptimizeAway(rx + 0x1.0p120); mem.doNotOptimizeAway(rx + 0x1.0p120);
} }
return if (s != 0) -rx else rx; return if (s != 0) -rx else rx;

View File

@ -6,6 +6,7 @@
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const mem = std.mem;
const expect = std.testing.expect; const expect = std.testing.expect;
/// Returns the arc-tangent of x. /// Returns the arc-tangent of x.
@ -67,7 +68,7 @@ fn atan32(x_: f32) f32 {
// |x| < 2^(-12) // |x| < 2^(-12)
if (ix < 0x39800000) { if (ix < 0x39800000) {
if (ix < 0x00800000) { if (ix < 0x00800000) {
math.doNotOptimizeAway(x * x); mem.doNotOptimizeAway(x * x);
} }
return x; return x;
} }
@ -165,7 +166,7 @@ fn atan64(x_: f64) f64 {
// |x| < 2^(-27) // |x| < 2^(-27)
if (ix < 0x3E400000) { if (ix < 0x3E400000) {
if (ix < 0x00100000) { if (ix < 0x00100000) {
math.doNotOptimizeAway(@as(f32, @floatCast(x))); mem.doNotOptimizeAway(@as(f32, @floatCast(x)));
} }
return x; return x;
} }

View File

@ -6,6 +6,7 @@
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const mem = std.mem;
const expect = std.testing.expect; const expect = std.testing.expect;
const maxInt = std.math.maxInt; const maxInt = std.math.maxInt;
@ -40,7 +41,7 @@ fn atanh_32(x: f32) f32 {
if (u < 0x3F800000 - (32 << 23)) { if (u < 0x3F800000 - (32 << 23)) {
// underflow // underflow
if (u < (1 << 23)) { if (u < (1 << 23)) {
math.doNotOptimizeAway(y * y); mem.doNotOptimizeAway(y * y);
} }
} }
// |x| < 0.5 // |x| < 0.5
@ -69,7 +70,7 @@ fn atanh_64(x: f64) f64 {
if (e < 0x3FF - 32) { if (e < 0x3FF - 32) {
// underflow // underflow
if (e == 0) { if (e == 0) {
math.doNotOptimizeAway(@as(f32, @floatCast(y))); mem.doNotOptimizeAway(@as(f32, @floatCast(y)));
} }
} }
// |x| < 0.5 // |x| < 0.5

View File

@ -8,6 +8,7 @@
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const mem = std.mem;
const expect = std.testing.expect; const expect = std.testing.expect;
/// Returns e raised to the power of x, minus 1 (e^x - 1). This is more accurate than exp(e, x) - 1 /// Returns e raised to the power of x, minus 1 (e^x - 1). This is more accurate than exp(e, x) - 1
@ -100,7 +101,7 @@ fn expm1_32(x_: f32) f32 {
// |x| < 2^(-25) // |x| < 2^(-25)
else if (hx < 0x33000000) { else if (hx < 0x33000000) {
if (hx < 0x00800000) { if (hx < 0x00800000) {
math.doNotOptimizeAway(x * x); mem.doNotOptimizeAway(x * x);
} }
return x; return x;
} else { } else {
@ -231,7 +232,7 @@ fn expm1_64(x_: f64) f64 {
// |x| < 2^(-54) // |x| < 2^(-54)
else if (hx < 0x3C900000) { else if (hx < 0x3C900000) {
if (hx < 0x00100000) { if (hx < 0x00100000) {
math.doNotOptimizeAway(@as(f32, @floatCast(x))); mem.doNotOptimizeAway(@as(f32, @floatCast(x)));
} }
return x; return x;
} else { } else {

View File

@ -6,6 +6,7 @@
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const mem = std.mem;
const expect = std.testing.expect; const expect = std.testing.expect;
/// Returns the natural logarithm of 1 + x with greater accuracy when x is near zero. /// Returns the natural logarithm of 1 + x with greater accuracy when x is near zero.
@ -56,7 +57,7 @@ fn log1p_32(x: f32) f32 {
if ((ix << 1) < (0x33800000 << 1)) { if ((ix << 1) < (0x33800000 << 1)) {
// underflow if subnormal // underflow if subnormal
if (ix & 0x7F800000 == 0) { if (ix & 0x7F800000 == 0) {
math.doNotOptimizeAway(x * x); mem.doNotOptimizeAway(x * x);
} }
return x; return x;
} }

View File

@ -6,6 +6,7 @@
const std = @import("../std.zig"); const std = @import("../std.zig");
const math = std.math; const math = std.math;
const mem = std.mem;
const expect = std.testing.expect; const expect = std.testing.expect;
const expo2 = @import("expo2.zig").expo2; const expo2 = @import("expo2.zig").expo2;
const maxInt = std.math.maxInt; const maxInt = std.math.maxInt;
@ -58,7 +59,7 @@ fn tanh32(x: f32) f32 {
} }
// |x| is subnormal // |x| is subnormal
else { else {
math.doNotOptimizeAway(ax * ax); mem.doNotOptimizeAway(ax * ax);
t = ax; t = ax;
} }
@ -96,7 +97,7 @@ fn tanh64(x: f64) f64 {
} }
// |x| is subnormal // |x| is subnormal
else { else {
math.doNotOptimizeAway(@as(f32, @floatCast(ax))); mem.doNotOptimizeAway(@as(f32, @floatCast(ax)));
t = ax; t = ax;
} }