authorgravatar for lewis.gaul@gmail.comLewis Gaul <lewis.gaul@gmail.com> 2024-05-25 22:28:53+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-17 05:04:59+02:00
log36d5392f03f4a8aa8de82ff0541e657d0abc24f8
tree3c53c64b4c49d349352fb54113fe6e82ee38cd51
parent650e358220dd82ae7037bb555c6d2af471d6c6cb

Add tests for log10()


1 files changed, 64 insertions(+), 27 deletions(-)

lib/compiler_rt/log10.zig+64-27
...@@ -7,7 +7,8 @@...@@ -7,7 +7,8 @@
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");8const builtin = @import("builtin");
9const math = std.math;9const math = std.math;
10const testing = std.testing;10const expect = std.testing.expect;
11const expectEqual = std.testing.expectEqual;
11const maxInt = std.math.maxInt;12const maxInt = std.math.maxInt;
12const arch = builtin.cpu.arch;13const arch = builtin.cpu.arch;
13const common = @import("common.zig");14const common = @import("common.zig");
...@@ -187,38 +188,74 @@ pub fn log10l(x: c_longdouble) callconv(.c) c_longdouble {...@@ -187,38 +188,74 @@ pub fn log10l(x: c_longdouble) callconv(.c) c_longdouble {
187 }188 }
188}189}
189190
190test "log10_32" {191test "log10f() special" {
191 const epsilon = 0.000001;192 try expectEqual(log10f(0.0), -math.inf(f32));
193 try expectEqual(log10f(-0.0), -math.inf(f32));
194 try expectEqual(log10f(1.0), 0.0);
195 try expectEqual(log10f(10.0), 1.0);
196 try expectEqual(log10f(0.1), -1.0);
197 try expectEqual(log10f(math.inf(f32)), math.inf(f32));
198 try expect(math.isNan(log10f(-1.0)));
199 try expect(math.isNan(log10f(-math.inf(f32))));
200 try expect(math.isNan(log10f(math.nan(f32))));
201 try expect(math.isNan(log10f(math.snan(f32))));
202}
192203
193 try testing.expect(math.approxEqAbs(f32, log10f(0.2), -0.698970, epsilon));204test "log10f() sanity" {
194 try testing.expect(math.approxEqAbs(f32, log10f(0.8923), -0.049489, epsilon));205 try expect(math.isNan(log10f(-0x1.0223a0p+3)));
195 try testing.expect(math.approxEqAbs(f32, log10f(1.5), 0.176091, epsilon));206 try expectEqual(log10f(0x1.161868p+2), 0x1.46a9bcp-1);
196 try testing.expect(math.approxEqAbs(f32, log10f(37.45), 1.573452, epsilon));207 try expect(math.isNan(log10f(-0x1.0c34b4p+3)));
197 try testing.expect(math.approxEqAbs(f32, log10f(89.123), 1.94999, epsilon));208 try expect(math.isNan(log10f(-0x1.a206f0p+2)));
198 try testing.expect(math.approxEqAbs(f32, log10f(123123.234375), 5.09034, epsilon));209 try expectEqual(log10f(0x1.288bbcp+3), 0x1.ef1300p-1);
210 try expectEqual(log10f(0x1.52efd0p-1), -0x1.6ee6dcp-3); // Disagrees with GCC in last bit
211 try expect(math.isNan(log10f(-0x1.a05cc8p-2)));
212 try expectEqual(log10f(0x1.1f9efap-1), -0x1.0075ccp-2);
213 try expectEqual(log10f(0x1.8c5db0p-1), -0x1.c75df8p-4);
214 try expect(math.isNan(log10f(-0x1.5b86eap-1)));
199}215}
200216
201test "log10_64" {217test "log10f() boundary" {
202 const epsilon = 0.000001;218 try expectEqual(log10f(0x1.fffffep+127), 0x1.344136p+5); // Max input value
219 try expectEqual(log10f(0x1p-149), -0x1.66d3e8p+5); // Min positive input value
220 try expect(math.isNan(log10f(-0x1p-149))); // Min negative input value
221 try expectEqual(log10f(0x1.000002p+0), 0x1.bcb7b0p-25); // Last value before result reaches +0
222 try expectEqual(log10f(0x1.fffffep-1), -0x1.bcb7b2p-26); // Last value before result reaches -0
223 try expectEqual(log10f(0x1p-126), -0x1.2f7030p+5); // First subnormal
224 try expect(math.isNan(log10f(-0x1p-126))); // First negative subnormal
225}
203226
204 try testing.expect(math.approxEqAbs(f64, log10(0.2), -0.698970, epsilon));227test "log10() special" {
205 try testing.expect(math.approxEqAbs(f64, log10(0.8923), -0.049489, epsilon));228 try expectEqual(log10(0.0), -math.inf(f64));
206 try testing.expect(math.approxEqAbs(f64, log10(1.5), 0.176091, epsilon));229 try expectEqual(log10(-0.0), -math.inf(f64));
207 try testing.expect(math.approxEqAbs(f64, log10(37.45), 1.573452, epsilon));230 try expectEqual(log10(1.0), 0.0);
208 try testing.expect(math.approxEqAbs(f64, log10(89.123), 1.94999, epsilon));231 try expectEqual(log10(10.0), 1.0);
209 try testing.expect(math.approxEqAbs(f64, log10(123123.234375), 5.09034, epsilon));232 try expectEqual(log10(0.1), -1.0);
233 try expectEqual(log10(math.inf(f64)), math.inf(f64));
234 try expect(math.isNan(log10(-1.0)));
235 try expect(math.isNan(log10(-math.inf(f64))));
236 try expect(math.isNan(log10(math.nan(f64))));
237 try expect(math.isNan(log10(math.snan(f64))));
210}238}
211239
212test "log10_32.special" {240test "log10() sanity" {
213 try testing.expect(math.isPositiveInf(log10f(math.inf(f32))));241 try expect(math.isNan(log10(-0x1.02239f3c6a8f1p+3)));
214 try testing.expect(math.isNegativeInf(log10f(0.0)));242 try expectEqual(log10(0x1.161868e18bc67p+2), 0x1.46a9bd1d2eb87p-1);
215 try testing.expect(math.isNan(log10f(-1.0)));243 try expect(math.isNan(log10(-0x1.0c34b3e01e6e7p+3)));
216 try testing.expect(math.isNan(log10f(math.nan(f32))));244 try expect(math.isNan(log10(-0x1.a206f0a19dcc4p+2)));
245 try expectEqual(log10(0x1.288bbb0d6a1e6p+3), 0x1.ef12fff994862p-1);
246 try expectEqual(log10(0x1.52efd0cd80497p-1), -0x1.6ee6db5a155cbp-3);
247 try expect(math.isNan(log10(-0x1.a05cc754481d1p-2)));
248 try expectEqual(log10(0x1.1f9ef934745cbp-1), -0x1.0075cda79d321p-2);
249 try expectEqual(log10(0x1.8c5db097f7442p-1), -0x1.c75df6442465ap-4);
250 try expect(math.isNan(log10(-0x1.5b86ea8118a0ep-1)));
217}251}
218252
219test "log10_64.special" {253test "log10() boundary" {
220 try testing.expect(math.isPositiveInf(log10(math.inf(f64))));254 try expectEqual(log10(0x1.fffffffffffffp+1023), 0x1.34413509f79ffp+8); // Max input value
221 try testing.expect(math.isNegativeInf(log10(0.0)));255 try expectEqual(log10(0x1p-1074), -0x1.434e6420f4374p+8); // Min positive input value
222 try testing.expect(math.isNan(log10(-1.0)));256 try expect(math.isNan(log10(-0x1p-1074))); // Min negative input value
223 try testing.expect(math.isNan(log10(math.nan(f64))));257 try expectEqual(log10(0x1.0000000000001p+0), 0x1.bcb7b1526e50dp-54); // Last value before result reaches +0
258 try expectEqual(log10(0x1.fffffffffffffp-1), -0x1.bcb7b1526e50fp-55); // Last value before result reaches -0
259 try expectEqual(log10(0x1p-1022), -0x1.33a7146f72a42p+8); // First subnormal
260 try expect(math.isNan(log10(-0x1p-1022))); // First negative subnormal
224}261}