| 1 | const std = @import("std"); |
| 2 | const math = std.math; |
| 3 | const expect = std.testing.expect; |
| 4 | |
| 5 | const Complex = @import("../compiler_rt.zig").Complex; |
| 6 | |
| 7 | const impl = @import("divc3.zig"); |
| 8 | const div_cf16 = impl.div_cf16; |
| 9 | const div_cf32 = impl.div_cf32; |
| 10 | const div_cf64 = impl.div_cf64; |
| 11 | const div_cf80 = impl.div_cf80; |
| 12 | const div_cf128 = impl.div_cf128; |
| 13 | |
| 14 | test "divc3" { |
| 15 | try testDiv(f16, div_cf16); |
| 16 | try testDiv(f32, div_cf32); |
| 17 | try testDiv(f64, div_cf64); |
| 18 | try testDiv(f80, div_cf80); |
| 19 | try testDiv(f128, div_cf128); |
| 20 | } |
| 21 | |
| 22 | fn testDiv(comptime T: type, comptime f: fn (Complex(T), Complex(T)) Complex(T)) !void { |
| 23 | { |
| 24 | const result = f(.{ .real = 1.0, .imag = 0.0 }, .{ .real = -1.0, .imag = 0.0 }); |
| 25 | try expect(result.real == -1.0); |
| 26 | try expect(math.isNegativeZero(result.imag)); |
| 27 | } |
| 28 | { |
| 29 | const result = f(.{ .real = 1.0, .imag = 0.0 }, .{ .real = -4.0, .imag = 0.0 }); |
| 30 | try expect(result.real == -0.25); |
| 31 | try expect(math.isNegativeZero(result.imag)); |
| 32 | } |
| 33 | { |
| 34 | // if the first operand is an infinity and the second operand is a finite number, then the |
| 35 | // resultult of the / operator is an infinity; |
| 36 | const result = f(.{ .real = -math.inf(T), .imag = 0.0 }, .{ .real = -4.0, .imag = 1.0 }); |
| 37 | try expect(math.isPositiveInf(result.real)); |
| 38 | try expect(math.isPositiveInf(result.imag)); |
| 39 | } |
| 40 | { |
| 41 | // if the first operand is a finite number and the second operand is an infinity, then the |
| 42 | // result of the / operator is a zero; |
| 43 | const result = f(.{ .real = 17.2, .imag = 0.0 }, .{ .real = -math.inf(T), .imag = 0.0 }); |
| 44 | try expect(math.isNegativeZero(result.real)); |
| 45 | try expect(math.isNegativeZero(result.imag)); |
| 46 | } |
| 47 | { |
| 48 | // if the first operand is a nonzero finite number or an infinity and the second operand is |
| 49 | // a zero, then the result of the / operator is an infinity |
| 50 | const result = f(.{ .real = 1.1, .imag = 0.1 }, .{ .real = 0.0, .imag = 0.0 }); |
| 51 | try expect(math.isPositiveInf(result.real)); |
| 52 | try expect(math.isPositiveInf(result.imag)); |
| 53 | } |
| 54 | } |