master
 1const std = @import("../../std.zig");
 2const testing = std.testing;
 3const math = std.math;
 4const cmath = math.complex;
 5const Complex = cmath.Complex;
 6
 7/// Returns the projection of z onto the riemann sphere.
 8pub fn proj(z: anytype) Complex(@TypeOf(z.re, z.im)) {
 9    const T = @TypeOf(z.re, z.im);
10
11    if (math.isInf(z.re) or math.isInf(z.im)) {
12        return Complex(T).init(math.inf(T), math.copysign(@as(T, 0.0), z.re));
13    }
14
15    return Complex(T).init(z.re, z.im);
16}
17
18test proj {
19    const a = Complex(f32).init(5, 3);
20    const c = proj(a);
21
22    try testing.expectEqual(5, c.re);
23    try testing.expectEqual(3, c.im);
24}