Commit Graph
271 Commits
Author SHA1 Message Date
Stephen Canon a5cc950a86 Merge pull request #111 from rxwei/complex-derivatives
Make 'Complex' differentiable.
2020-04-22 16:43:46 -04:00
Richard Wei 488e250259 Make 'Complex' differentiable.
* Conform `Complex` to `Differentiable`.
* Define derivatives for `init(_:_:)`, `real`, `imaginary`, `conjugate`, `+(_:_:)`, `-(_:_:)`, `*(_:_:)`, `/(_:_:)`.

Gated under `#if canImport(_Differentiation)`.
2020-04-22 13:35:36 -07:00
Stephen Canon 59444343c4 Somewhat better implementation of pow(x,n) for Float16. 2020-04-10 16:16:25 -04:00
Stephen Canon ee082efdaf Fix bug for very large exponents pow(Float/Double, Int).
Just-added tests expose this issue, where the split of n into high/low parts could produce parts with different signs. If both x**high and x**low then overflow and underflow, the resulting computation would be 0*inf (or inf*0) and produce NaN instead of either zero or infinity.
2020-04-10 11:51:57 -04:00
Stephen Canon ff6a0ff2a5 Fix bug for very large exponents pow(Float/Double, Int).
Just-added tests expose this issue, where the split of n into high/low parts could produce parts with different signs. If both x**high and x**low then overflow and underflow, the resulting computation would be 0*inf (or inf*0) and produce NaN instead of either zero or infinity.
2020-04-10 11:46:22 -04:00
Stephen Canon a35f5ba889 Add Real conformance for Float16. 2020-04-08 15:14:48 -04:00
Stephen Canon 014ce562a4 Update README.md 2020-02-21 09:22:40 -05:00
Stephen Canon 9dba38cc1a Update README.md 2020-02-21 09:22:40 -05:00
Stephen Canon 0fa2cd458e Update README.md 2020-02-21 09:22:40 -05:00
Stephen Canon 76954c06a7 Back to trailing 'Module' 2020-02-21 09:22:40 -05:00
Stephen Canon 4352c3a6a1 Put an underscore between the module prefix and name.
Ideally we'd be able to use Numerics.Module instead of underscore, but we can't always get what we want.
2020-02-21 09:22:40 -05:00
Stephen Canon 43052f0819 Prefix modules with "Numerics"; use underscored prefix for NumericsShims. 2020-02-21 09:22:40 -05:00
Robert Thompson 5ea7711e02 Probably a slightly faster way to get trailingZeroBitCOunt 2020-02-19 15:15:42 -05:00
Robert Thompson b74c1ce133 Fix trailingZeroBitCount as per @nixberg
Also add a couple tests for it
2020-02-14 16:23:37 -05:00
Robert Thompson aaeb9029e9 Another fix for conversion of multi-word Ints 2020-01-29 10:42:52 -05:00
Robert Thompson 52e7e70caf Actual fix for multi-word integer types 2020-01-29 10:07:34 -05:00
Robert Thompson caeeaaa9dd Another fix for arm32 and actually for anything with multi-word ints
UInt64, Int64, etc have more than one word on 32-bit architectures
2020-01-29 09:55:10 -05:00
Robert Thompson feeac39506 Whoops, this is better 2020-01-28 17:53:23 -05:00
Robert Thompson 19951768df Another case where we'd get wrong negatives possibly 2020-01-28 17:51:45 -05:00
Robert Thompson 87900161d6 Normalize the remainder! 2020-01-28 17:36:55 -05:00
Robert Thompson 7d6e5cda3e Clean up division a bit more 2020-01-28 16:02:30 -05:00
Robert Thompson e4f5257d0a fix division
Re-write _findQhat from scratch, add check for division by single digit
number in _div
2020-01-28 14:05:22 -05:00
Robert Thompson 7026eb4085 more tests for division 2020-01-27 12:31:26 -05:00
Stephen Canon 016cd6a2fc AlgebraicField should conform to SignedNumeric, not just Numeric.
Because a field necessarily has additive inverses, SignedNumeric conformance is appropriate. (SignedNumeric is poorly named; it doesn't actually mean that a type has a "sign", only that there's a negation operation).
2020-01-24 10:42:11 -05:00
Ben Rimmington eda432142d [Complex] Encode and decode using unkeyedContainer 2020-01-22 18:34:20 +00:00
Robert Thompson 90d5ddd1f6 Fix failing tests (@benrimminton: it turned out simple)
If the last computed digit of a BinaryFloatingPoint source is > Int.max,
we need to add an extra zero digit to the end so we're not negative!
2020-01-21 16:59:28 -05:00
Ben Rimmington 6e85aa2bbd [BigInt] Revert the BinaryFloatingPoint conversion 2020-01-21 19:47:19 +00:00
Ben Rimmington 3501fa7c61 [BigInt] Restore precondition message for inf/nan 2020-01-21 17:30:47 +00:00
Ben Rimmington ca75d2d124 [BigInt] Move pow(_:_:) into test-only extension 2020-01-21 16:24:51 +00:00
Stephen Canon 7bd2909875 Merge pull request #91 from apple/FieldProtocol
Introduce AlgebraicField protocol
2020-01-20 13:35:59 -05:00
Stephen Canon 323542cba1 Add short notes to README docs on AlgebraicField. 2020-01-19 16:06:31 -05:00
Stephen Canon 98f3d25fe8 Rename Field -> AlgebraicField
We might walk this back in the future, but for the short-term let's avoid stomping on the generic term "Field".
2020-01-19 15:53:35 -05:00
Ben Rimmington 05a45984d9 [BigInt] Update signum(), add testSignum() 2020-01-19 19:48:07 +00:00
Ben Rimmington 98023c3575 [BigInt] Combine *= and << into simpler <<= 2020-01-19 10:31:39 +00:00
Ben Rimmington 1b733de54a [BigInt] Fix initializers with BinaryFloatingPoint 2020-01-18 19:44:27 +00:00
Ben Rimmington b03af80076 [BigInt] Change self = -self to self.negate() 2020-01-17 07:33:36 +00:00
Robert Thompson d36d9ce02e Remove superfluous CustomStringConvertible impl 2020-01-16 17:08:52 -05:00
Robert Thompson fac716fdb2 Fix implementation of <
Previously, all BigInts were less than themselves. This is no longer
true. Discovered thanks to @lorentey and @benrimmington re: discussion
on explicit implementation of `!=`.
2020-01-16 15:15:37 -05:00
Robert Thompson 7ca51a3e50 normalize words in the BinaryInteger bitPattern init
as per @lorentey
2020-01-16 14:25:46 -05:00
Robert Thompson 1ddbbfe0d1 Rename internal init as per @lorentey 2020-01-16 14:24:24 -05:00
Stephen Canon 8cbda03867 s/euclidean/Euclidean/ 2020-01-16 11:12:46 -05:00
Stephen Canon b6839260cb Add some clarification to documentation of .reciprocal. 2020-01-16 11:11:56 -05:00
Ben Rimmington 2410717a17 [BigInt] Update the SignedNumeric prefix operator 2020-01-16 13:12:29 +00:00
Robert Thompson 0b121fd774 Fix failing tests (@benrimmington)
We were not correctly handling the case where two single-word operands
added up to a number > Int.max. Also, negate (and `-`) was not removing
excess words, resulting in identical numbers not comparing equal!
2020-01-15 15:13:58 -05:00
Robert Thompson 72f1cb3554 Merge branch 'BigInt' of github.com:rothomp3/swift-numerics into BigInt 2020-01-15 14:15:36 -05:00
Robert Thompson 0e58379b4f explicitly call out TAOCP by Knuth 2020-01-15 14:15:27 -05:00
Ben Rimmington 8c378528de [BigInt] Update the Codable conformance 2020-01-15 00:59:46 +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
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