mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-10-29 11:15:47 +08:00
53 lines
1.9 KiB
Zig
53 lines
1.9 KiB
Zig
const std = @import("std");
|
|
const builtin = @import("builtin");
|
|
const fmod_f80 = @import("fmod.zig").fmod_f80;
|
|
const testing = std.testing;
|
|
|
|
fn test_fmod_f80(a: f80, b: f80, exp: f80) !void {
|
|
const res = fmod_f80(a, b);
|
|
try testing.expect(exp == res);
|
|
}
|
|
|
|
fn test_fmod_f80_nans() !void {
|
|
try testing.expect(std.math.isNan(fmod_f80(1.0, std.math.nan(f80))));
|
|
try testing.expect(std.math.isNan(fmod_f80(1.0, -std.math.nan(f80))));
|
|
try testing.expect(std.math.isNan(fmod_f80(std.math.nan(f80), 1.0)));
|
|
try testing.expect(std.math.isNan(fmod_f80(-std.math.nan(f80), 1.0)));
|
|
}
|
|
|
|
fn test_fmod_f80_infs() !void {
|
|
try testing.expect(fmod_f80(1.0, std.math.inf(f80)) == 1.0);
|
|
try testing.expect(fmod_f80(1.0, -std.math.inf(f80)) == 1.0);
|
|
try testing.expect(std.math.isNan(fmod_f80(std.math.inf(f80), 1.0)));
|
|
try testing.expect(std.math.isNan(fmod_f80(-std.math.inf(f80), 1.0)));
|
|
}
|
|
|
|
test fmod_f80 {
|
|
try test_fmod_f80(6.4, 4.0, 2.4);
|
|
try test_fmod_f80(6.4, -4.0, 2.4);
|
|
try test_fmod_f80(-6.4, 4.0, -2.4);
|
|
try test_fmod_f80(-6.4, -4.0, -2.4);
|
|
try test_fmod_f80(3.0, 2.0, 1.0);
|
|
try test_fmod_f80(-5.0, 3.0, -2.0);
|
|
try test_fmod_f80(3.0, 2.0, 1.0);
|
|
try test_fmod_f80(1.0, 2.0, 1.0);
|
|
try test_fmod_f80(0.0, 1.0, 0.0);
|
|
try test_fmod_f80(-0.0, 1.0, -0.0);
|
|
try test_fmod_f80(7046119.0, 5558362.0, 1487757.0);
|
|
try test_fmod_f80(9010357.0, 1957236.0, 1181413.0);
|
|
try test_fmod_f80(9223372036854775807, 10.0, 7.0);
|
|
|
|
// Denormals
|
|
const a1: f80 = 0x0.76e5_9a51_1a92_9ca4p-16381;
|
|
const b1: f80 = 0x0.2e97_1c3c_8e7d_e03ap-16381;
|
|
const exp1: f80 = 0x0.19b7_61d7_fd96_dc30p-16381;
|
|
try test_fmod_f80(a1, b1, exp1);
|
|
const a2: f80 = 0x0.76e5_9a51_1a92_9ca4p-16381;
|
|
const b2: f80 = 0x0.0e97_1c3c_8e7d_e03ap-16381;
|
|
const exp2: f80 = 0x0.022c_b86c_a6a3_9ad4p-16381;
|
|
try test_fmod_f80(a2, b2, exp2);
|
|
|
|
try test_fmod_f80_nans();
|
|
try test_fmod_f80_infs();
|
|
}
|