1const std = @import("std");
2const math = std.math;
3const expect = std.testing.expect;
4
5const Complex = @import("../compiler_rt.zig").Complex;
6const impl = @import("mulc3.zig");
7const mul_cf16 = impl.mul_cf16;
8const mul_cf32 = impl.mul_cf32;
9const mul_cf64 = impl.mul_cf64;
10const mul_cf80 = impl.mul_cf80;
11const mul_cf128 = impl.mul_cf128;
12
13test "mulc3" {
14 try testMul(f16, mul_cf16);
15 try testMul(f32, mul_cf32);
16 try testMul(f64, mul_cf64);
17 try testMul(f80, mul_cf80);
18 try testMul(f128, mul_cf128);
19}
20
21fn testMul(comptime T: type, comptime f: fn (Complex(T), Complex(T)) Complex(T)) !void {
22 {
23 const result = f(.{ .real = 1.0, .imag = 0.0 }, .{ .real = -1.0, .imag = 0.0 });
24 try expect(result.real == -1.0);
25 try expect(math.isPositiveZero(result.imag));
26 }
27 {
28 const result = f(.{ .real = 1.0, .imag = 0.0 }, .{ .real = -4.0, .imag = 0.0 });
29 try expect(result.real == -4.0);
30 try expect(math.isPositiveZero(result.imag));
31 }
32 {
33 // if one operand is an infinity and the other operand is a nonzero finite number or an infinity,
34 // then the result of the * operator is an infinity;
35 const result = f(.{ .real = math.inf(T), .imag = -math.inf(T) }, .{ .real = 1.0, .imag = 0.0 });
36 try expect(math.isPositiveInf(result.real));
37 try expect(math.isNegativeInf(result.imag));
38 }
39 {
40 // if one operand is an infinity and the other operand is a nonzero finite number or an infinity,
41 // then the result of the * operator is an infinity;
42 const result = f(.{ .real = math.inf(T), .imag = -1.0 }, .{ .real = 1.0, .imag = math.inf(T) });
43 try expect(math.isPositiveInf(result.real));
44 try expect(math.isPositiveInf(result.imag));
45 }
46}