apple / swift-numerics

Advanced mathematical types and functions for Swift
Apache License 2.0
1.69k stars 147 forks source link

Make `Complex.magnitude` use the `Magnitude` type of the underlying `RealType` #283

Closed markuswntr closed 8 months ago

markuswntr commented 8 months ago

Currently, the type of Complex.magnitude is equal to the underlying Real type of the complex number. This is fine for Float[16|32|64] et al, but I believe incorrect, since Real does not necessary require Magnitude to always be of the same type.

NevinBR commented 8 months ago

Real refines FloatingPoint which refines SignedNumeric with the constraint where Magnitude == Self.

See the declaration of FloatingPoint in the standard library.

markuswntr commented 8 months ago

Thanks so much for the feedback!

I did not know this is a constraint on FloatingPoint – closing this PR then.