swift-numerics
swift-numerics copied to clipboard
Should `Complex.magnitude` use `.magnitude` instead of `abs()`?
https://github.com/apple/swift-numerics/blob/f96c6c20666aefcccb63630659eae15623e47837/Sources/Complex/Complex.swift#L227
Currently, Complex.magnitude is calculated using the abs() free function instead of the .magnitude property on its real and imaginary parts. I don’t know if there is any difference at runtime (I suspect not, as the conditional checks in Swift.abs() should get optimized away), but from a code-reading standpoint it seems reasonable to prefer implementing the Complex.magnitude property in terms of the RealType.magnitude property.
Yeah, these produce identical code (you can check for yourself pretty easily using godbolt.org, by the way).
@NevinBR OK to close this?