Commit Graph
34 Commits
Author SHA1 Message Date
Ben Rimmington b39dd05db3 [BigIntTests] Update the testExample() method 2020-01-15 06:44:41 +00:00
Ben Rimmington 1cb69383a5 [BigIntTests] Wrap to 80 characters 2020-01-15 03:53:16 +00:00
Ben Rimmington c9d72fc3ae [BigIntTests] Trim trailing whitespace 2020-01-15 03:34:14 +00:00
Ben Rimmington 4ec520a726 [BigIntTests] Update the testCodable() method
Top-level JSON fragments might fail on Linux, so encode Range<BigInt> instead.

<https://bugs.swift.org/browse/SR-6163>
2020-01-15 03:30:50 +00:00
Ben Rimmington 3cf0b0cf74 [BigInt] Update the LosslessStringConvertible init
This performs 6x faster (measured with a 1000-digit string).

But it doesn't fix the testMinMaxDescriptions() failures.
2020-01-15 00:47:04 +00:00
Ben Rimmington f6a3d2d4e4 [BigIntTests] Add testMinMaxDescriptions() method
This currently fails for:

BigInt(Int64.min) - 2
BigInt(Int64.min) - 1
BigInt(Int64.max) + 1
BigInt(Int64.max) + 2
2020-01-15 00:17:17 +00:00
Robert Thompson 036ab5fe94 Conform to Codable with default implementation
Since we have only a single stored property which itself already
conforms to `Codable`, there's no need to go down the rabbit hole of
explicitly implementing it. If someone wants to do it to produce a more
human-readable JSON (eg, as a string instead of an array of integers),
then you're welcome to.
2020-01-14 15:07:08 -05:00
Robert Thompson 7c6e2ce0d8 Explicitly implement public mutating func negate()
As per the TODO put in by @benrimmington. I'm not 100% sure this is
actually better than the default implementation provided by
`SignedNumeric`, but there's a chance it is.
2020-01-14 15:00:38 -05:00
Robert Thompson 821fcbd6a4 Update following suggestions from @benrimmington
Includes reformatting to use 2-space indentation and the correct file
headers, among other simplifications.
2019-12-30 15:46:18 -05:00
Robert Thompson cb56525312 Address PR feedback
Eliminate unnecessary math function calls, and also handle floating
point edge cases better.
2019-12-30 10:33:00 -05:00
Robert Thompson bc2f9fb7c6 Use NumericShims for math functions 2019-12-30 10:33:00 -05:00
Stephen Canon b7e48c538c Refactor RealTests
Redesign and rename sanityCheck to assertClose; basic function is the same, but the implementation is a bit more straightforward and it now reports an accurate ulp error and can track maximum error if you want (we want this for some use cases).

Also move the basic sanity checks into one file and the tests that more thoroughly excercise a single function into their own files.
2019-12-27 16:35:41 -05:00
Stephen Canon de5399615c Additional test coverage of saturating values.
Also skip out of tests that won't compile and wouldn't make sense anyway on 32b systems.
2019-11-29 23:11:15 -05:00
Stephen Canon f7842a76db Capitalization search/replace-o 2019-11-29 23:00:45 -05:00
Stephen Canon 65aac0be46 Add test cases to stress pow(_:Float/Double,:Int)
These are the hardest cases to get right; most of the fail at present.

Also some improvements to sanityCheck to handle negative values correctly and treat infinity as the next binade up (which isn't ideal for general use, but is good for this sort of rough testing.)
2019-11-29 22:54:03 -05:00
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 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
Ole Begemann d875fdbd0b Delete RealTests.allTests
This broke building the tests on Linux because of a missing symbol (ComplexTests.allTests), and with `--enable-test-discovery` we don't need this anyway.
2019-11-12 21:25:42 +01:00
Stephen Canon 2760aa4ba4 Replace LinuxMain.swift with a fatalError
Direct users to run with --enable-test-discovery until it becomes the default.
2019-11-12 14:45:59 -05:00
Stephen Canon a27ffc7c63 Merge pull request #57 from tachoknight/master
Added LinuxMain.swift so numerics can be used on Linux
2019-11-12 14:27:12 -05:00
Stephen Canon e24586e2b1 Defer to libm cbrt for root(x,3).
This lets us get exact cases right only platforms where cbrt(x) has sub-ulp accuracy. It doesn't get all the other non-power-of-two roots quite right, and is still dependent on the host system, but 2 and 3 are the most common roots people take by far, so it's a good first step.
2019-11-10 22:02:53 -05:00
Noah Wilder 6ac60de457 Added two more test cases for Complex division by zero 2019-11-09 15:18:30 -05:00
Noah Wilder d5e0caa6f8 Added test cases for division by zero 2019-11-09 15:11:55 -05:00
Ron Olson 86e9087ab5 Added LinuxMain.swift so numerics can be used on Linux 2019-11-08 15:10:38 -06: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 fe37d9896e Further complex divide benchamark and performance work (#29)
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.
2019-11-04 11:37:51 -05:00
Stephen Canon a2353c82df Further benchmark improvments, workaround hypot bug. (#28)
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).
2019-11-02 21:40:00 -04:00
Stephen Canon 78f1cf691e Remove files that are no longer needed. 2019-11-01 21:22:04 -04: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 4a2409ffcd Give expm1 and logp1 more explicit names
These names are relatively standard, but more cryptic than they might be. Let's try using something else; I think that there's a decent chance we'll end up going back to the short/common names eventually, but it's worth experimenting with these a little bit.
2019-07-22 11:07:10 -04:00
Steve (Numerics) Canon fa9422ec6e Remove NumericShims module; we don't need it thanks to silgen_name. 2019-07-19 16:29:53 -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