Commit Graph

33 Commits

Author SHA1 Message Date
Xiaodi Wu ac4c3c6018 Remove redundant conformances 2018-02-09 22:46:18 -06:00
Xiaodi Wu cef815d55c Improve wording in a doc comment [NFC] 2017-08-01 21:32:23 -05:00
Xiaodi Wu af461df38c Improve wording in a doc comment [NFC] 2017-08-01 21:28:35 -05:00
Xiaodi Wu 2a3aba73af Expand tests for Rational and fix an initializer implementation 2017-07-15 12:51:43 -05:00
Xiaodi Wu 237366a24f Restore some uses of @_transparent 2017-07-08 17:17:36 -05:00
Xiaodi Wu acc17bd238 Refine handling of complex infinity and NaN 2017-07-08 16:32:34 -05:00
Xiaodi Wu 0a6a45a9d5 Expand testing based on code coverage reporting (#8)
This PR adds tests to improve code coverage. In addition:

* The implementation of `Rational.isProper is corrected` for negative values.


* Add tests for Float and Double extensions

* Adjust accuracy for Glibc

* Add tests for RNG initialization using device entropy

* Expand testing of Rational and fix implementation of Rational.isProper

* Further expand testing of Rational

* Expand tests for Float and Double extensions

* Expand tests for Rational

* Adjust accuracy for Glibc

* Expand tests for Float and Double extensions

* Adjust accuracy for Glibc

* Re-adjust accuracy for Glibc

* Expand testing of Complex
2017-07-04 13:01:35 -05:00
Xiaodi Wu 89a82f52d6 Implement and use an internal function for combining hashes 2017-06-11 16:12:21 -05:00
Xiaodi Wu 390d835d4b Conform Complex and Rational to Codable 2017-06-11 14:28:20 -05:00
Xiaodi Wu 4fe964e9f3 Make additional changes for Jazzy 2017-06-04 00:36:17 -05:00
Xiaodi Wu 62f8f19727 Remove initializers from FloatingPointMath 2017-06-03 19:31:45 -05:00
Xiaodi Wu 2d8adf5bc3 Adjust code organization for Jazzy 2017-06-03 18:46:52 -05:00
Xiaodi Wu 8441b85a52 Make minor adjustments for Jazzy 2017-06-03 04:02:50 -05:00
Xiaodi Wu 11907a190c Add PRNG and Random (#3)
This PR introduces a protocol named `PRNG` for pseudo-random number generators, which is class-constrained and refines `IteratorProtocol` and `Sequence`. Extension methods on `PRNG` should not be susceptible to "modulo bias" problems that can occur when `Element.max - Element.min + 1` is not a power of two.

It also introduces a (final) class named `Random`, which conforms to `PRNG` and implements the `xorshift128+` algorithm, and another (final) class named `Random.Xoroshiro`, which conforms to `PRNG` and implements the `xoroshiro128+` algorithm. Much work remains to be done, including testing the code using [TestU01](http://simul.iro.umontreal.ca/testu01/tu01.html).


* Initial implementation of Random

* Implement discrete uniform distribution

* Make minor change to Random.init?()

* Create protocol PRNG and make changes to Random accordingly

* Revert "Modify FloatingPointMath to refine BinaryFloatingPoint"

* Update README.md

* Simplify some implementations

* Update README.md

* Make minor stylistic changes

* Update implementation of Random.init?()

* Implement MT19937 and xoroshiro128+

* Improve implementation of PRNG.uniform<T : BinaryFloatingPoint>()

* Implement PRNG.exponential and PRNG.weibull

* Refine implementation of Random.MersenneTwister

* Revise description of Xoroshiro128+

* Implement PRNG.bernoulli functions

* Add tests for xorshift128+ and xoroshiro128+, fix and update implementations, make minor stylistic changes

* Change visibility of MT19937 parameters

* Remove Random.MersenneTwister, avoid undefined behavior in PRNG._entropy

* Update to avoid heterogeneous comparison

* Revert "Update to avoid heterogeneous comparison"

* Document methods on PRNG

* Update README.md
2017-06-02 20:45:19 -05:00
Xiaodi Wu abbb554d2c Make minor stylistic changes to Rational 2017-05-07 04:02:49 -05:00
Xiaodi Wu 22867ff2c2 Make minor changes to Rational.isCanonical and Rational.hashValue 2017-05-07 03:55:36 -05:00
Xiaodi Wu be292e1346 Improve implementation of Rational.== 2017-05-07 02:41:11 -05:00
Xiaodi Wu 6bdfbd4cd0 Fix implementation of Rational comparison 2017-05-07 00:54:22 -05:00
Xiaodi Wu b866fd43d3 Improve implementation of Rational comparison 2017-05-07 00:07:57 -05:00
Xiaodi Wu 358a0066e7 Add SignedInteger conformance to Big 2017-05-01 04:07:20 -05:00
Xiaodi Wu 9d6a19970b Make minor changes to Rational and Big 2017-05-01 00:27:56 -05:00
Xiaodi Wu 1736e69b7f Add partial implementation of arbitrary-precision integers
...and correct some implementations in Rational.

Although it was possible to implement many of the simpler algorithms using a two's complement representation, it proved to be difficult to implement multiplication or division without taking the absolute value. Some reading suggests that most (if not all) arbitrary-precision integer implementations use sign-and-magnitude representation. Thus, I have switched back to that representation (which was one option that I had already explored).

This PR contains working implementations of comparison, addition, subtraction, long multiplication, and negation. Additional testing is required to verify correctness.

No attempt has yet been made to implement division or bit shifting, and no updated implementation is included for other bitwise operations. It remains unclear to me whether generic use of such operations always assumes two's complement representation, or whether it is appropriate to simply perform these bitwise operations on the native sign-and-magnitude representation.

Future directions include implementation of more sophisticated multiplication algorithms such as Karatsuba.
2017-04-30 18:48:39 -05:00
Xiaodi Wu a1580a53d6 Ensure sign of rational zero is always positive 2017-04-27 20:38:21 -05:00
Xiaodi Wu 90c0736330 Add tests for Rational conversion, fix implementations, restore some uses of @_transparent 2017-04-24 18:13:46 -05:00
Xiaodi Wu 255b0885b0 Add conversion initializers, reorganize and document 2017-04-24 13:05:14 -05:00
Xiaodi Wu 59af27bbf7 Add initializers for Rational conversion to/from floating point 2017-04-24 02:23:01 -05:00
Xiaodi Wu ab16bc0c10 Remove some uses of @_transparent 2017-04-23 22:27:36 -05:00
Xiaodi Wu 3f16ab3c90 Fix two nits 2017-04-22 23:13:20 -05:00
Xiaodi Wu 4e98ff46e9 Make a small improvement in comparing two Rational values 2017-04-22 23:11:03 -05:00
Xiaodi Wu 97769c04ad Fun with full-width arithmetic (NFC) 2017-04-22 14:11:38 -05:00
Xiaodi Wu 7d3e092746 Add more documentation 2017-04-22 01:57:04 -05:00
Xiaodi Wu 0b1ba3bdc0 Add doc comments and make some minor fix-ups 2017-04-21 23:37:02 -05:00
Xiaodi Wu 4779b68088 Add Rational type and integer protocol conformances (#1)
Add Rational type and integer protocol conformances
2017-04-21 19:23:31 -05:00