divc3_test.zig (2360B) - 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 __divhc3 = @import("./divhc3.zig").__divhc3; 7 const __divsc3 = @import("./divsc3.zig").__divsc3; 8 const __divdc3 = @import("./divdc3.zig").__divdc3; 9 const __divxc3 = @import("./divxc3.zig").__divxc3; 10 const __divtc3 = @import("./divtc3.zig").__divtc3; 11 12 test "divc3" { 13 try testDiv(f16, __divhc3); 14 try testDiv(f32, __divsc3); 15 try testDiv(f64, __divdc3); 16 try testDiv(f80, __divxc3); 17 try testDiv(f128, __divtc3); 18 } 19 20 fn testDiv(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 == -0.25); 39 try expect(result.imag == 0.0); 40 } 41 { 42 // if the first operand is an infinity and the second operand is a finite number, then the 43 // result of the / operator is an infinity; 44 const a: T = -math.inf(T); 45 const b: T = 0.0; 46 const c: T = -4.0; 47 const d: T = 1.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 the first operand is a finite number and the second operand is an infinity, then the 55 // result of the / operator is a zero; 56 const a: T = 17.2; 57 const b: T = 0.0; 58 const c: T = -math.inf(T); 59 const d: T = 0.0; 60 61 const result = f(a, b, c, d); 62 try expect(result.real == -0.0); 63 try expect(result.imag == 0.0); 64 } 65 { 66 // if the first operand is a nonzero finite number or an infinity and the second operand is 67 // a zero, then the result of the / operator is an infinity 68 const a: T = 1.1; 69 const b: T = 0.1; 70 const c: T = 0.0; 71 const d: T = 0.0; 72 73 const result = f(a, b, c, d); 74 try expect(result.real == math.inf(T)); 75 try expect(result.imag == math.inf(T)); 76 } 77 }