zig

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

mulc3_test.zig (2007B) - Raw


      1 const std = @import("std");
      2 const math = std.math;
      3 const expect = std.testing.expect;
      4 
      5 const Complex = @import("./mulc3.zig").Complex;
      6 const __mulhc3 = @import("./mulhc3.zig").__mulhc3;
      7 const __mulsc3 = @import("./mulsc3.zig").__mulsc3;
      8 const __muldc3 = @import("./muldc3.zig").__muldc3;
      9 const __mulxc3 = @import("./mulxc3.zig").__mulxc3;
     10 const __multc3 = @import("./multc3.zig").__multc3;
     11 
     12 test "mulc3" {
     13     try testMul(f16, __mulhc3);
     14     try testMul(f32, __mulsc3);
     15     try testMul(f64, __muldc3);
     16     try testMul(f80, __mulxc3);
     17     try testMul(f128, __multc3);
     18 }
     19 
     20 fn testMul(comptime T: type, comptime f: fn (T, T, T, T) callconv(.c) Complex(T)) !void {
     21     {
     22         const a: T = 1.0;
     23         const b: T = 0.0;
     24         const c: T = -1.0;
     25         const d: T = 0.0;
     26 
     27         const result = f(a, b, c, d);
     28         try expect(result.real == -1.0);
     29         try expect(result.imag == 0.0);
     30     }
     31     {
     32         const a: T = 1.0;
     33         const b: T = 0.0;
     34         const c: T = -4.0;
     35         const d: T = 0.0;
     36 
     37         const result = f(a, b, c, d);
     38         try expect(result.real == -4.0);
     39         try expect(result.imag == 0.0);
     40     }
     41     {
     42         // if one operand is an infinity and the other operand is a nonzero finite number or an infinity,
     43         // then the result of the * operator is an infinity;
     44         const a: T = math.inf(T);
     45         const b: T = -math.inf(T);
     46         const c: T = 1.0;
     47         const d: T = 0.0;
     48 
     49         const result = f(a, b, c, d);
     50         try expect(result.real == math.inf(T));
     51         try expect(result.imag == -math.inf(T));
     52     }
     53     {
     54         // if one operand is an infinity and the other operand is a nonzero finite number or an infinity,
     55         // then the result of the * operator is an infinity;
     56         const a: T = math.inf(T);
     57         const b: T = -1.0;
     58         const c: T = 1.0;
     59         const d: T = math.inf(T);
     60 
     61         const result = f(a, b, c, d);
     62         try expect(result.real == math.inf(T));
     63         try expect(result.imag == math.inf(T));
     64     }
     65 }