zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

fmodx_test.zig (1917B) - Raw


      1 const std = @import("std");
      2 const builtin = @import("builtin");
      3 const fmod = @import("fmod.zig");
      4 const testing = std.testing;
      5 
      6 fn test_fmodx(a: f80, b: f80, exp: f80) !void {
      7     const res = fmod.__fmodx(a, b);
      8     try testing.expect(exp == res);
      9 }
     10 
     11 fn test_fmodx_nans() !void {
     12     try testing.expect(std.math.isNan(fmod.__fmodx(1.0, std.math.nan(f80))));
     13     try testing.expect(std.math.isNan(fmod.__fmodx(1.0, -std.math.nan(f80))));
     14     try testing.expect(std.math.isNan(fmod.__fmodx(std.math.nan(f80), 1.0)));
     15     try testing.expect(std.math.isNan(fmod.__fmodx(-std.math.nan(f80), 1.0)));
     16 }
     17 
     18 fn test_fmodx_infs() !void {
     19     try testing.expect(fmod.__fmodx(1.0, std.math.inf(f80)) == 1.0);
     20     try testing.expect(fmod.__fmodx(1.0, -std.math.inf(f80)) == 1.0);
     21     try testing.expect(std.math.isNan(fmod.__fmodx(std.math.inf(f80), 1.0)));
     22     try testing.expect(std.math.isNan(fmod.__fmodx(-std.math.inf(f80), 1.0)));
     23 }
     24 
     25 test "fmodx" {
     26     try test_fmodx(6.4, 4.0, 2.4);
     27     try test_fmodx(6.4, -4.0, 2.4);
     28     try test_fmodx(-6.4, 4.0, -2.4);
     29     try test_fmodx(-6.4, -4.0, -2.4);
     30     try test_fmodx(3.0, 2.0, 1.0);
     31     try test_fmodx(-5.0, 3.0, -2.0);
     32     try test_fmodx(3.0, 2.0, 1.0);
     33     try test_fmodx(1.0, 2.0, 1.0);
     34     try test_fmodx(0.0, 1.0, 0.0);
     35     try test_fmodx(-0.0, 1.0, -0.0);
     36     try test_fmodx(7046119.0, 5558362.0, 1487757.0);
     37     try test_fmodx(9010357.0, 1957236.0, 1181413.0);
     38     try test_fmodx(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_fmodx(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_fmodx(a2, b2, exp2);
     49 
     50     try test_fmodx_nans();
     51     try test_fmodx_infs();
     52 }