Commit Graph
126 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 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
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 3a4cc1c623 Merge pull request #1 from benrimmington/BigInt
[BigInt] Reorganize into extensions by conformance
2020-01-14 14:47:02 -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 cced27a6c0 Missed a spot where things should be alphabetical 2019-12-30 15:50:03 -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 ea2b6f8deb BigInt no longer depends on NumericsShims 2019-12-30 10:33:00 -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 2c12891617 Merge pull request #87 from stephentyrone/cleanup-real-conformances
Split conformance of Float, Double, Float80 to Real out
2019-12-27 13:42:01 -08:00
Stephen Canon f25a870cec Merge pull request #86 from stephentyrone/real-test-cleanup
Refactor RealTests
2019-12-27 13:41:33 -08: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 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 7ff707f6f8 Merge pull request #83 from stephentyrone/pown
Initial pass at pow(Self, Int) for Float and Double
0.0.3
2019-11-29 23:13:19 -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 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