14 Commits
Author SHA1 Message Date
Stephen Canon f6c2c34910 Rename unsafeLengthSquared -> lengthSquared
Also further tweak polar init for Complex to allow (-infinity, θ) when θ is not finite.
2019-11-20 16:15:10 -05:00
Stephen CanonandRichard Wei 5931d036ab Update Sources/Complex/Complex.swift
Co-Authored-By: Richard Wei <rxrwei@gmail.com>
2019-11-20 14:56:31 -05:00
Stephen Canon 565839d673 Address behavior of Complex.init(length:phase:)
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
2019-11-20 14:32:19 -05:00
Stephen Canon 0ddfd0ead7 Split Codable conformance of Complex into Encodable and Decodable. NFC.
Also make conformance to CustomDebugStringConvertible unconditional using String(reflecting:) on x and y.
2019-11-10 14:32:09 -05:00
Stephen Canon 5d4368257e Merge pull request #36 from Sajjon/fix_typos_in_code
Fix typos in source code
2019-11-08 09:33:23 -05:00
Sajjon c423f9592b Fix typos in source code 2019-11-08 08:39:07 +01:00
Noah Wilder 0308def714 Added setters for real and imaginary properties of Complex 2019-11-07 23:51:40 -05:00
Stephen Canon f59e64a1aa Rename ElementaryFunctions module -> Real
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.
2019-11-06 12:40:12 -05:00
Stephen Canon e387654448 More complex testing, and split it apart into multiple files.
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.
2019-11-01 21:16:15 -04:00
Stephen Canon 9b3bd5af26 Beef up complex multiply/divide testing, fix an edge-case that it turned up.
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.
2019-10-31 16:00:34 -04:00
Stephen Canon eb76aa632b Update license headers, add CONTRIBUTING.md and umbrella module 2019-10-30 16:11:20 -04:00
Steve (Numerics) Canon 6908e3951a Re-arrange some stuff within Complex.swift, expand documentation
Also add a note about relative vs absolute error in Complex multiplication and division.
2019-08-05 15:24:08 -04:00
Steve (Numerics) Canon 4df7603179 fixed_layout -> frozen 2019-07-22 11:18:48 -04:00
Steve (Numerics) Canon 8aab7a90f8 Initial project setup for swift-numerics
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.
2019-07-06 15:27:21 -04:00