Commit Graph

571 Commits

Author SHA1 Message Date
Lee Bousfield 426034ba09
Switch doctests to match functions 2017-07-09 08:30:22 -04:00
Lee Bousfield aaa4ab357f
Clarify what "newer versions of Rust" applies to 2017-07-08 17:21:32 -04:00
Lee Bousfield f0fa65a9d5
Fix float NaN pos/neg assumptions 2017-07-08 17:15:35 -04: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 b1b034f438 num: bump to 0.1.39 2017-06-09 11:03:50 -07:00
Josh Stone d2defd67f2 bigint: bump to 0.1.39 2017-06-09 11:02:16 -07:00
Josh Stone 81e932b671 rational: bump to 0.1.38 2017-06-09 10:58:40 -07:00
Josh Stone 796adf5dfa traits: bump to 0.1.39 2017-06-09 10:56:13 -07:00
Homu 5cd52741c4 Auto merge of #301 - cuviper:revert-296, r=cuviper
Revert "Auto merge of #296 - vks:no_std, r=cuviper"

This reverts commit 8b5d4ac24e, reversing
changes made to ef752e4687.

See #297 -- it's a breaking change to feature-gate existing APIs.
2017-06-10 02:26:53 +09:00
Josh Stone fe34d17aaf Revert "Auto merge of #296 - vks:no_std, r=cuviper"
This reverts commit 8b5d4ac24e, reversing
changes made to ef752e4687.
2017-06-09 10:12:50 -07:00
Homu 681bbf8659 Auto merge of #300 - cuviper:no-default-subcrates, r=cuviper
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-10 02:00:14 +09: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
Homu f809c79d9f Auto merge of #299 - dotdash:rational-fix, r=cuviper
Fix building without the num-bigint feature
2017-06-10 01:54:07 +09:00
Björn Steinbrink 33ca084e85 Fix building without the num-bigint feature 2017-06-09 18:45:44 +02:00
Josh Stone 7bf9a6ccf2 num: bump to 0.1.38 2017-06-08 23:53:47 -07:00
Josh Stone 1033388e02 rational: bump to 0.1.37 2017-06-08 23:50:30 -07:00
Josh Stone a6d4d6e67d bigint: bump to 0.1.38 2017-06-08 23:48:27 -07:00
Josh Stone 9a9765a1db complex: bump to 0.1.38 2017-06-08 23:46:08 -07:00
Josh Stone ae438d3608 traits: bump to 0.1.38 2017-06-08 23:42:41 -07:00
Homu 8b5d4ac24e Auto merge of #296 - vks:no_std, r=cuviper
traits: Introduce std feature

This makes it possible to build `traits` without `std`. For this a new
trait `BasicFloat` was introduced, implementing some basic functionality
that works with `core`. Most notably this is lacking functions like
`cos`, `sin`, etc.

`Float` is not available without `std`.

Refs #216.
2017-06-09 15:25:08 +09:00
Vinzent Steinberg ba73ba2af0 Avoid infinite recursion on `no_std` 2017-06-08 10:02:39 +02:00
Vinzent Steinberg b7d2a99d09 Add word of caution about `Float` and `no_std` 2017-06-07 12:22:26 +02:00
Vinzent Steinberg 63ce0f04ae Don't duplicate `num_traits::pow` 2017-06-07 12:17:16 +02:00
Vinzent Steinberg f8a61962ba Use native `to_degrees`/`to_radians` 2017-06-07 12:05:53 +02:00
Vinzent Steinberg d201882c61 Fix typo 2017-06-07 11:59:28 +02:00
Vinzent Steinberg 128e456342 Travis, please test traits with no_std 2017-06-02 12:01:31 +02:00
Vinzent Steinberg 169105bb84 Implement `Float::{min, max}` for `no_std` 2017-06-02 11:47:46 +02:00
Vinzent Steinberg 6253669ef4 Mark methods in `Float` whether they require `std`
This removes the `BasicFloat` trait.
2017-06-02 11:47:45 +02:00
Vinzent Steinberg 351dfc6383 traits: Introduce std feature
This makes it possible to build `traits` without `std`. For this a new
trait `BasicFloat` was introduced, implementing some basic functionality
that works with `core`. Most notably this is lacking functions like
`cos`, `sin`, etc.

`Float` is not available without `std`.

Refs #216.
2017-05-31 13:44:39 +02:00
Homu ef752e4687 Auto merge of #291 - cuviper:hasher, r=cuviper
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.

(extends #287)
2017-05-07 14:48:07 +09: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
Homu f9d36e6d9b Auto merge of #283 - cuviper:more-num, r=cuviper
Add new traits for reference and assignment operators

There are two new "utility" traits covering the basic operators:
`Add`, `Sub`, `Mul`, `Div`, and `Rem`.

- `NumOps<Rhs, Output>`: operators with an arbitrary operand and output.
- `NumAssignOps<Rhs>`: assignment operators with an arbitrary operand.

Then the new collection of numeric traits are:

- `Num`: effectively unchanged, just taking operands by value.
- `NumRef`: `Num` adding reference operands on the right side.
- `RefNum`: `&T` operators, with either `T` or `&T` on the right side.
  - This does not specify `T: Num`, as rust-lang/rust#20671 means that
    could only add a constraint, without implying its presence for use.
- `NumAssign`: `Num` adding assignment operators by value.
- `NumAssignRef`: `NumAssign` adding reference assignment operators.
  - Nothing actually implements this yet!

Acknowledgement: this is roughly based on [@andersk's suggestion](https://github.com/rust-num/num/issues/94#issuecomment-269073071).
2017-05-07 13:40:39 +09:00
Josh Stone 3ead4a16b5 Implement RefNum more generically 2017-05-06 21:35:38 -07:00
Josh Stone 21b520ea15 Add new traits for reference and assignment operators
There are two new "utility" traits covering the basic operators:
`Add`, `Sub`, `Mul`, `Div`, and `Rem`.

- `NumOps<Rhs, Output>`: operators with an arbitrary operand and output.
- `NumAssignOps<Rhs>`: assignment operators with an arbitrary operand.

Then the new collection of numeric traits are:

- `Num`: effectively unchanged, just taking operands by value.
- `NumRef`: `Num` adding reference operands on the right side.
- `RefNum`: `&T` operators, with either `T` or `&T` on the right side.
  - This does not specify `T: Num`, as rust-lang/rust#20671 means that
    could only add a constraint, without implying its presence for use.
- `NumAssign`: `Num` adding assignment operators by value.
- `NumAssignRef`: `NumAssign` adding reference assignment operators.
  - Nothing actually implements this yet!

Acknowledgement: this is roughly based on [@andersk's suggestion][1].

[1] https://github.com/rust-num/num/issues/94#issuecomment-269073071
2017-05-06 21:35:38 -07:00
Homu ef08fe2f96 Auto merge of #286 - yoanlcq:missing-impls-for-wrapping, r=cuviper
impl remaining num-traits for std::num::Wrapping<T>

This is a (late) follow-up for [https://github.com/rust-num/num/pull/279](https://github.com/rust-num/num/pull/279) since I realized that implementing `Num` for `Wrapping<T>` was merely half of the work.

This PR makes `Wrapping<T>` implement the remaining appropriate traits, granting it the ability to really be used a complete substitute for its primitive integer counterparts.
Some benefits are :
- Less refactoring for users using `num`'s traits replacing some primitives by their `Wrapping` counterpart (same for the opposite);
- Since `Wrapping<T>` is from `std`, nobody except us can `impl` our traits for it, so people don't have to create their own.
2017-05-07 13:26:44 +09:00
Josh Stone 9115df6179 Merge branch 'master' into missing-impls-for-wrapping 2017-05-06 21:25:28 -07:00
Homu 51e95550fc Auto merge of #285 - sdroege:ratio-approx-from-float, r=cuviper
rational: Implement approximation from floats and FromPrimitive for v…

…arious types

FromPrimitive is implemented for i8/16/32/64 and BigInt.

https://github.com/rust-num/num/issues/282
2017-05-06 13:27:39 +09:00
Homu d5ca939959 Auto merge of #290 - king6cong:master, r=cuviper
add missing '`' in README.md

None
2017-05-03 16:03:29 +09:00
king6cong ea45567f0c add missing '`' in README.md 2017-05-03 14:41:43 +08:00
Sebastian Dröge f74753089b rational: Implement approximation from floats and FromPrimitive for various types
FromPrimitive is implemented for i8/16/32/64 and BigInt.

https://github.com/rust-num/num/issues/282
2017-05-02 02:28:27 +03:00
Yoan Lecoq 9d8c808db6 comment out wrapping_is_signed test to make Rust 1.8 happy 2017-05-01 14:11:10 +02:00
Yoan Lecoq fd50c9196b Added trait bounds tests for Wrapping 2017-05-01 13:42:30 +02:00