For now, this mostly allows one to write code generic over Real and Complex types. TBD whether it should also include finite fields, or be restricted to characteristic-zero. Also bikeshedding to be done on exactly what operations should fall into this protocol and what it should be named. This is just to get discussion started.
Instead of being failable, adopt the following policy:
- If length is zero or infinity, the phase does not matter.
- Otherwise, the phase must be finite or a precondition failure occurs.
Discussion here: https://github.com/apple/swift-numerics/issues/51
No change to the protocols involved, purely a change so that the module that users import shares the name of the feature they are most likely to be using, rather than a somewhat-esoteric implementation detail.
Instead of using @_specialize, mark the rescaled division @_aEIC + inline(never). This more closely matches the semantics of what we want, gets better performance, and fixes the issue for every type, not only the types on which we specialize. This is probably as good as we can do for now.
Added benchmark version that defeats hoisting part of the divide computation outside of the workloop (but kept the old ones as well, because *both* are good representitives of what we want to track). Also found a bug in macOS hypot very close to the overflow boundary for the naive algorithm, and added a workaround (also reported the bug).
Added some performance tests for multiply/divide, and some transparent annotations to the source where necessary for performance reasons. Additionally removed the Linux test information, since that's no longer necessary with test discovery in swiftpm.
Also added a new `var reciprocal: Self?` for Complex that allows for more efficient divisions when a divisor is used repeatedly, while avoiding the accuracy hazard of using `1/self` when a value is poorly scaled.
Previously we simply checked if the result of the naive divide was normal; this isn't quite right, because it could miss unsafeLengthSquared underflowing without going all the way to zero, resulting in significant loss of intermediate precision. Instead check if unsafeLengthSquared itself is non-normal. This is actually a cheaper check, and gets us everything we need, so it's a win-win.
Proof: if w.unsafeLengthSquared is normal, then so is w.conjugate.divided(by: unsafeLengthSquared), which means that we're left only with the multiply. Our goal is to be only as good as multiply is, so that's good enough.
Two modules to begin with:
- ElementaryFunctions
- Complex
Added README.md files describing each module very roughly, and a project
README to describe goals and process.