This PR adds tests for BinaryInteger.pow and for default implementations in Math and Real. In addition:
The default implementation of cubeRoot is corrected and removed from Math to Real.
A correction is made for an error in the default implementation of Math.phi.
Special values are now handled in the default implementation of Real.hypot.
This PR also includes an incidental simplification of some operator implementations in Complex, which will simplify later testing.
* Add tests for Math and Real, fix default implementations
* Reorder tests for Linux [NFC]
* Remove repetition in Complex operator implementations [NFC]
* Add tests for integer exponentiation
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
...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.