Commit Graph
73 Commits
Author SHA1 Message Date
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
Ben Rimmington 4d7e4e9b97 [BigInt] Rename private _findQhat method 2020-01-14 04:44:44 +00:00
Ben Rimmington 3c916262e0 [BigInt] Update bitWidth and magnitude properties 2020-01-14 02:46:47 +00:00
Ben Rimmington 831f06ac78 [BigInt] Add the MARK and TODO comments 2020-01-14 02:44:38 +00:00
Ben Rimmington d15400e6ab [BigInt] Add the Words typealias 2020-01-14 02:39:59 +00:00
Ben Rimmington 5be3b4e526 [BigInt] Move the BinaryInteger methods 2020-01-14 02:38:53 +00:00
Ben Rimmington acd8568864 [BigInt] Move the BinaryInteger operators 2020-01-14 02:36:23 +00:00
Ben Rimmington 11d5225f3b [BigInt] Move the BinaryInteger properties 2020-01-14 02:26:50 +00:00
Ben Rimmington 19d3491df4 [BigInt] Move the BinaryInteger initializers 2020-01-14 02:25:37 +00:00
Ben Rimmington 819ebd90c4 [BigInt] Move the SignedNumeric conformance 2020-01-14 02:16:00 +00:00
Ben Rimmington 5b84051f2a [BigInt] Move the Numeric conformance 2020-01-14 02:14:30 +00:00
Ben Rimmington cb5e7f3c7a [BigInt] Move the AdditiveArithmetic conformance 2020-01-14 02:09:45 +00:00
Ben Rimmington 5cb9b95ce8 [BigInt] Move the ExpressibleByIntegerLiteral conformance 2020-01-14 02:05:42 +00:00
Ben Rimmington 5db4a69e57 [BigInt] Move the LosslessStringConvertible conformance 2020-01-14 02:04:16 +00:00
Ben Rimmington 2419741a7c [BigInt] Move the CustomStringConvertible conformance 2020-01-14 02:00:12 +00:00
Ben Rimmington 368caf5b3f [BigInt] Move the Comparable conformance 2020-01-14 01:58:03 +00:00
Ben Rimmington a799618103 [BigInt] Move the Hashable conformance 2020-01-14 01:56:43 +00:00
Ben Rimmington dbf743b314 [BigInt] Move the Equatable conformance 2020-01-14 01:54:58 +00:00
Ben Rimmington 2f40de6195 [BigInt] Move _isNegative and _digits properties 2020-01-14 01:52:01 +00:00
Ben Rimmington 38073d2ab5 [BigInt] Move init(words:) and init(bitPattern:) 2020-01-14 01:49:26 +00:00
Ben Rimmington 2863c44182 [BigInt] Remove the isSigned property 2020-01-14 01:42:43 +00:00
Robert Thompson e490f1fc66 Explicitly implment hash(into:) per @benrimmington feedback
Technically, I believe the auto-generated implementation was already
doing exactly this, since `words` is the only stored property of
`BigInt`. However, it rarely hurts to be explicit.
2020-01-13 14:45:48 -05:00
Robert Thompson 67858690eb Update LosslessStringConvertible initializer
as per further suggestions from @Wildchild9, adding in the removing
leading zeros part I missed.
2019-12-30 16:01:04 -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 b46dcf96c6 oops, change both occurrences of digitsAndDash 2019-12-30 15:13:26 -05:00
Robert ThompsonandBen Rimmington eceae6d7bd Update Sources/BigInt/BigInt.swift
As per benrimmington's excellent suggestion

Co-Authored-By: Ben Rimmington <me@benrimmington.com>
2019-12-30 15:12:20 -05:00
Robert Thompson ac50a90a60 whoops 2019-12-30 10:44:48 -05:00
Robert Thompson 524dc69ae1 slightly refactor LosslessStringConvertible initializer as per PR feedback 2019-12-30 10:41:40 -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
Robert Thompson 96d41bcf9f Initial commit of BigInt 2019-12-30 10:33:00 -05:00
Stephen Canon 3d637e1302 Split conformance of Float, Double, Float80 to Real out into separate files.
Also reformat these files to be more closely in line with Swift conventions.
2019-12-27 16:39:26 -05:00
Stephen Canon 5bf2f828ef Initial pass at implementing pow(Self,Int) with desired semantics.
We don't need to do anything special for Float80, but Float and Double require some handholding because Int values are not always representable.
2019-11-29 22:56:14 -05:00
Stephen Canon 5e978d85a2 Add inline decls of lgamma_r and friends on Linux, too. 2019-11-22 09:47:36 -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 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
Ole Begemann 0ed7e786b5 Remove broken link in Real module readme
The link target for `[Real]` wasn't defined. I decided toremove the link altogether because the readme would essentially link to itself.
2019-11-12 17:28:36 +01:00
Stephen CanonandXiaodi Wu 5d783ce458 Update Sources/Real/ScalarConformances.swift
Co-Authored-By: Xiaodi Wu <xiaodi.wu@gmail.com>
2019-11-10 22:19:39 -05:00
Stephen CanonandXiaodi Wu 3fbc22cbe3 Update Sources/Real/ScalarConformances.swift
Co-Authored-By: Xiaodi Wu <xiaodi.wu@gmail.com>
2019-11-10 22:19:30 -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
Stephen Canon 6d904ea56c Add documentation for AdditiveArithmetic conformance of ElementaryFunctions 2019-11-10 21:12:37 -05:00
NevinBR 6195693e3a Made ElementaryFunctions refine AdditiveArithmetic 2019-11-10 19:58:07 -05:00
Stephen Canon 3519620ac6 Merge pull request #65 from stephentyrone/split-codable-make-debugDecription-unconditional
Split Codable conformance of Complex into Encodable and Decodable. NFC.
2019-11-10 14:59:18 -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
NevinBR ab19494638 Fixed typo in a comment 2019-11-10 10:35:22 -05:00
Noah Wilder b46bd9a83e Fixed Complex division by zero to return .infinity 2019-11-09 01:37:27 -05:00