Commit Graph

68 Commits

Author SHA1 Message Date
bors[bot] ebc36b3e55 Merge #313
313: Scalar operations across all integer types r=cuviper

With my apologies for opening a new PR, and also for the 8 month delay, this continues the work started in #237 - the discussion there outlines the goals I was aiming for. I suppose this supersedes that PR and the other one can now be closed.

This PR adds support for Add, Sub, Mul, Div and Rem operations involving one BigInt/BigUint and one primitive integer, with operands in either order, and any combination of owned/borrowed arguments.
2017-07-12 05:16:29 +00:00
Josh Stone e5434dc659 Add assert_scalar_op! for DRYer testing 2017-07-11 21:59:10 -07:00
Josh Stone 6afac825d9 test and fix more scalar add cases 2017-07-11 17:27:19 -07:00
Josh Stone 18a5bfcd0b fix endianness of to/from_doublebigdigit calls 2017-07-11 17:22:11 -07:00
Josh Stone 18cc1902fb inline i32_abs_as_u32 and i64_abs_as_u64 2017-07-11 17:01:15 -07:00
Keith Wansbrough ef83e851e7 Add keywords and categories to subcrates too. 2017-07-11 09:30:42 +01:00
Sam Cappleman-Lynes 1fb03ca18a Make new code work on rustc-1.8.0
- Don't apply attributes to statements (1.12.0)
 - Don't use checked_abs (1.13.0)
2017-06-30 00:39:37 +01:00
Sam Cappleman-Lynes 2a3cd41820 Add scalar ops for all remaining integer types 2017-06-29 22:18:54 +01:00
Sam Cappleman-Lynes fd87d87db3 Fix normalization in scalar addition 2017-06-29 20:40:54 +01:00
Sam Cappleman-Lynes 99873d06e5 Scalar operations on integer types up to 32 bits 2017-06-29 18:29:14 +01:00
Sam Cappleman-Lynes 94d570697c Add operations on i32 to BigInt 2017-06-29 17:20:17 +01:00
Sam Cappleman-Lynes 9b0392d235 Add scalar division to BigInt 2017-06-29 16:19:11 +01:00
Sam Cappleman-Lynes 8b1288ea01 Add scalar multiplication to BigInt 2017-06-29 15:46:07 +01:00
Sam Cappleman-Lynes 79448cbdf9 Add scalar subtraction to BigInt 2017-06-29 15:15:59 +01:00
Sam Cappleman-Lynes 80feea2722 Also implement scalar addition for BigInt 2017-06-29 14:07:44 +01:00
Sam Cappleman-Lynes 1e26bdde81 Remove unnecessary normalization 2017-06-29 13:53:08 +01:00
Sam Cappleman-Lynes d0bfb54eee All variants of dividing BigUint by BigDigit
Allow the division to occur with either operand order and with any
combination of owned and borrowed arguments.
2017-06-29 13:38:00 +01:00
Sam Cappleman-Lynes 51408a9b3b All variants of subtracting BigDigit from BigUint
Allow the subtraction to occur with either operand order and with any
combination of owned and borrowed arguments.
2017-06-29 10:12:53 +01:00
Sam Cappleman-Lynes 5738141b7c Distinction for commutative scalar ops 2017-06-29 09:59:42 +01:00
Sam Cappleman-Lynes fd2f516a5d All variants of multiplying BigUint by BigDigit
Allow the multiplication to occur with either operand order and with any
combination of owned and borrowed arguments.
2017-06-29 09:56:15 +01:00
Sam Cappleman-Lynes e5ed503141 Implement all variants of adding BigDigit to BigUint
Allow the addition to occur with either operand order, and with any combination
of owned and borrowed arguments.
2017-06-29 08:41:46 +01:00
Sam Cappleman-Lynes 784d26bbf8 Scalar division of a BigUint by a BigDigit
A BigUint can be divided by a BigDigit - this is one of several
operations being implemented to allow scalar operations on BigInt and
BigUint across the board.
2017-06-28 16:59:35 +01:00
Sam Cappleman-Lynes 530e2f6022 Fix typo in comment in division algorithm 2017-06-28 16:26:40 +01:00
Sam Cappleman-Lynes 7b7799eab7 Scalar subtraction of a BigDigit from a BigUint
A BigDigit can be subtracted from a BigUint - this is one of several
operations being implemented to allow scalar operations on BigInt and
BigUint across the board.
2017-06-28 16:24:56 +01:00
Sam Cappleman-Lynes a2a28c682e Scalar addition of BigDigit to BigUint
A BigDigit can be added to a BigUint - this is one of several
operations being implemented to allow scalar operations on BigInt and
BigUint across the board.
2017-06-28 16:11:02 +01:00
Sam Cappleman-Lynes e520bdad0d Add scalar multiplication to BigUint, BigInt
BigUint and BigInt can now be multiplied by a BigDigit, re-using the same buffer for the output, thereby reducing allocations and copying.
2017-06-28 14:02:45 +01:00
Josh Stone 8964c65f38 bigint: apply a consistent order of conversion methods 2017-06-21 17:52:24 -07:00
Josh Stone 8dd6890ddc Merge commit 'refs/pull/304/head' of github.com:rust-num/num 2017-06-21 17:33:46 -07:00
Eduardo Pinho 15f9334955 De-generalize `twos_complement' helper function 2017-06-20 01:31:49 +01:00
Eduardo Pinho 61cfdc37b3 BigInt two's complement adjustments
- rename `_twos_complement_` methods to just `_signed_`
- make `from_` variants take &[u8]
- refactor helper functions twos_complement (they take byte slice but use a generic function underneath)
- fix issues in `to_signed_` functions (only two's complement negative numbers; perform byte extension where needed)
- add tests to `to_signed_` methods
2017-06-18 01:42:56 +01:00
Phaiax 563e4dc509 from_radix_be/le for BigInt 2017-06-16 23:28:49 +02:00
Eduardo Pinho 1660590125 Add BigInt 2's complement conversions
- add methods `from_twos_complement_bytes_le`, `from_twos_complement_bytes_be`, `to_twos_complement_bytes_le`, and `to_twos_complement_bytes_be` to `BigInt`.
- add respective tests
2017-06-16 17:58:04 +01:00
Phaiax 1ea02d8d0c Add _be/_le postfix to from/to_radix functions (BigInt) 2017-06-13 15:36:59 +02:00
Phaiax fc09503d3d Add fn from_radix() for radix > 36. 2017-06-11 20:08:43 +02:00
Phaiax 1ab07df709 Add fn to_radix() for radix > 36. 2017-06-11 18:31:44 +02:00
Josh Stone d2defd67f2 bigint: bump to 0.1.39 2017-06-09 11:02:16 -07:00
Josh Stone 8b9cdaada2 Test and fix subcrates with --no-default-features
- The CI script now tests them all with --no-default-features.
- bigint: testing needs rand even when the main feature is disabled.
- rational: gate `FromPrimitive for Ratio<BigInt>` on having bigint.
2017-06-09 09:54:50 -07:00
Josh Stone a6d4d6e67d bigint: bump to 0.1.38 2017-06-08 23:48:27 -07:00
Josh Stone 1b895a8632 Get the default hasher indirectly
`DefaultHasher` wasn't stable until 1.13, at which point all the other
hashers were deprecated, so it's not easy for us to name a hasher type
to use for testing.  However, `RandomState` has been stable since 1.7,
and it implements `BuildHasher` that has a `Hasher` associated type.
2017-05-06 22:23:31 -07:00
Patrick Jackson 71a15212a1 Replace deprecated SipHasher. 2017-04-28 18:48:50 -07:00
Josh Stone d23e3f32b8 num-bigint-0.1.37 2017-03-08 11:14:32 -08:00
Josh Stone 0b6cae0dc7 bigint: Create the parsing error better for nested `+`
If a `+` is encountered in the middle of parsing a BigUint, this should
generate an `ParseIntError::InvalidDigit`.  Since we can't create that
directly, we get it by trying to parse a `u64` from this point, but of
course `+` is a perfectly valid prefix to a `u64`.

Now we include the previous character in the string passed to `u64`, so
it has proper parsing context to understand what's in error.

Fixes #268.
2017-03-06 13:23:40 -08:00
Josh Stone 4b8c71fbec bigint: Cleanup unused imports 2017-03-06 13:20:30 -08:00
Josh Stone 1a66ee9e80 Add licenses to subcrates 2017-02-26 13:39:23 -08:00
bluss ff2a350e98 Use the integer32 playground 2016-11-02 19:51:10 +01:00
bluss e4a6956e5a Add doc(html_root_url) and other doc attrs to each crate
Also update to use https instead of http. This avois mixed content
degradation on docs.rs.

The doc root URLs are correct as they are, the URL does not include the
crate name itself.
2016-11-01 02:14:23 +01:00
Aleksey Kladov ec6ce78458 Minor, style and comment typo 2016-10-05 18:47:30 +03:00
Josh Stone c8ed8ff87b num, bigint, complex, rational, traits: 0.1.35 2016-08-18 08:28:34 -07:00
Richard Janis Goldschmidt a4ccb797cf Allow serde version in [0.7,0.9) 2016-08-17 12:20:08 +02:00
Josh Stone 5c3d759d6c bigint: inline bits() methods 2016-08-10 22:23:28 -07:00