Commit Graph

27 Commits

Author SHA1 Message Date
Xiaodi Wu a4a9ac7368 Define an exponentiation operator 2017-08-27 00:19:57 -05:00
Xiaodi Wu 00d7fab46f Add a missing newline [NFC] 2017-07-16 17:04:17 -05:00
Xiaodi Wu 644d19222e Remove one use of @_transparent 2017-07-16 16:56:04 -05:00
Xiaodi Wu 7e13418232 Remove Complex.polar (it's poorly named and trivial) 2017-07-16 16:55:22 -05:00
Xiaodi Wu 10ea1eab12 Fix implementation of Complex.tanh and expand tests 2017-07-16 16:47:10 -05:00
Xiaodi Wu 9553e20023 Make a minor stylistic change [NFC] 2017-07-16 13:59:52 -05:00
Xiaodi Wu aee282025f Expand and add tests for Complex 2017-07-15 18:41:30 -05:00
Xiaodi Wu 913da91d25 Refine Complex.description, add more tests for Complex 2017-07-09 17:43:22 -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 b9d507ee05 Remove power(of:) 2017-06-14 00:06:37 -05:00
Xiaodi Wu e426e168b4 Expand testing (#4)
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
2017-06-12 20:03:31 -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 ea3af8458f Rename FloatingPointMath to Real 2017-06-07 07:15:24 -05:00
Xiaodi Wu eeb4dc4e8c Update implementation of Complex.hyperbolicTangent and add tests for special values 2017-06-06 01:41:03 -05:00
Xiaodi Wu d6876b3675 Update README.md and a comment 2017-06-04 08:46:46 -05:00
Xiaodi Wu 9e17f688ef Touch up some comments 2017-06-04 08:27:12 -05:00
Xiaodi Wu 4fe964e9f3 Make additional changes for Jazzy 2017-06-04 00:36:17 -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 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 7d3e092746 Add more documentation 2017-04-22 01:57:04 -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
Xiaodi Wu d24b1e89d5 Add typealiases, change Complex.squareRoot() logic, add some tests. 2017-04-02 20:11:39 -05:00
Xiaodi Wu c3e53384a0 Initial commit 2017-04-02 19:31:31 -05:00