Commit Graph

16 Commits

Author SHA1 Message Date
Xiaodi Wu 0f1fb6cb2b Rename RationalRoundingRule to RoundingRule 2017-05-07 04:23:40 -05:00
Xiaodi Wu 76ae7dfef2 Make a minor stylistic change 2017-05-07 02:49:50 -05:00
Xiaodi Wu dd8bc4a31d Improve implementation of Rational.+ and Rational.* 2017-05-07 02:21:13 -05:00
Xiaodi Wu cf7b620481 Make a minor stylistic change 2017-05-03 20:15:56 -05:00
Xiaodi Wu 52e6ab3fd2 Minor stylistic changes 2017-05-01 04:25:43 -05:00
Xiaodi Wu 88b652dd05 Make minor stylistic changes, remove commented-out code 2017-04-30 19:15:34 -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 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 195d5b091c Add additional tests for Rational and make minor stylistic adjustments 2017-04-23 21:41:59 -05:00
Xiaodi Wu 3f16ab3c90 Fix two nits 2017-04-22 23:13:20 -05:00
Xiaodi Wu 97769c04ad Fun with full-width arithmetic (NFC) 2017-04-22 14:11:38 -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