Doing complex number computations in an inner loop, speed in the important thing here! Should Complex(f64).init be avoided or not?? Two examples, which would be faster??:
inline fn sub(a: anytype, b: @TypeOf(a)) @TypeOf(a) {
return @TypeOf(a).init(a.re - b.re, a.im - b.im);
}
or
inline fn sub(a: anytype, b: @TypeOf(a)) @TypeOf(a) {
var c: @TypeOf(a) = undefined;
c.re = a.re - b.re;
c.im = a.im - b.im;
return c;
}
Would there be other alternatives that would be faster?
(Yes, there is the complex math function for subtraction, but this is just example. The question is about how to "create" the returned variable.)
I believe they would be exactly the same, but am unsure, I could not get this working on godbolt. Thanks in advance.