1const std = @import("std");
2const builtin = @import("builtin");
3const fmod_f80 = @import("fmod.zig").fmod_f80;
4const testing = std.testing;
5
6fn test_fmod_f80(a: f80, b: f80, exp: f80) !void {
7 const res = fmod_f80(a, b);
8 try testing.expect(exp == res);
9}
10
11fn test_fmod_f80_nans() !void {
12 try testing.expect(std.math.isNan(fmod_f80(1.0, std.math.nan(f80))));
13 try testing.expect(std.math.isNan(fmod_f80(1.0, -std.math.nan(f80))));
14 try testing.expect(std.math.isNan(fmod_f80(std.math.nan(f80), 1.0)));
15 try testing.expect(std.math.isNan(fmod_f80(-std.math.nan(f80), 1.0)));
16}
17
18fn test_fmod_f80_infs() !void {
19 try testing.expect(fmod_f80(1.0, std.math.inf(f80)) == 1.0);
20 try testing.expect(fmod_f80(1.0, -std.math.inf(f80)) == 1.0);
21 try testing.expect(std.math.isNan(fmod_f80(std.math.inf(f80), 1.0)));
22 try testing.expect(std.math.isNan(fmod_f80(-std.math.inf(f80), 1.0)));
23}
24
25test fmod_f80 {
26 try test_fmod_f80(6.4, 4.0, 2.4);
27 try test_fmod_f80(6.4, -4.0, 2.4);
28 try test_fmod_f80(-6.4, 4.0, -2.4);
29 try test_fmod_f80(-6.4, -4.0, -2.4);
30 try test_fmod_f80(3.0, 2.0, 1.0);
31 try test_fmod_f80(-5.0, 3.0, -2.0);
32 try test_fmod_f80(3.0, 2.0, 1.0);
33 try test_fmod_f80(1.0, 2.0, 1.0);
34 try test_fmod_f80(0.0, 1.0, 0.0);
35 try test_fmod_f80(-0.0, 1.0, -0.0);
36 try test_fmod_f80(7046119.0, 5558362.0, 1487757.0);
37 try test_fmod_f80(9010357.0, 1957236.0, 1181413.0);
38 try test_fmod_f80(9223372036854775807, 10.0, 7.0);
39
40 // Denormals
41 const a1: f80 = 0x0.76e5_9a51_1a92_9ca4p-16381;
42 const b1: f80 = 0x0.2e97_1c3c_8e7d_e03ap-16381;
43 const exp1: f80 = 0x0.19b7_61d7_fd96_dc30p-16381;
44 try test_fmod_f80(a1, b1, exp1);
45 const a2: f80 = 0x0.76e5_9a51_1a92_9ca4p-16381;
46 const b2: f80 = 0x0.0e97_1c3c_8e7d_e03ap-16381;
47 const exp2: f80 = 0x0.022c_b86c_a6a3_9ad4p-16381;
48 try test_fmod_f80(a2, b2, exp2);
49
50 try test_fmod_f80_nans();
51 try test_fmod_f80_infs();
52}