Commit Graph

738 Commits

Author SHA1 Message Date
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
Yoan Lecoq 3b7a775f38 Remove Signed Wrapping test because Wrapping doesn't impl Neg in Rust 1.8 2017-04-30 10:45:51 +02:00
Yoan Lecoq 3896c64dc7 Attempt to work around E0425 in test macros on Rust 1.8 2017-04-30 10:33:35 +02:00
Yoan Lecoq 3f6ea76e60 Removed some #[inline] hints again 2017-04-30 10:17:44 +02:00
Yoan Lecoq 807584688c Added some tests for Wrapping<T>'s impls 2017-04-30 10:17:06 +02:00
Yoan Lecoq b90cfaaa7f Revert "impl PrimInt for Wrapping<T>"
This reverts commit 579466d95c.
2017-04-30 08:32:59 +02:00
Yoan Lecoq f4e0b47ceb Revert #[inline] hints 2017-04-30 08:32:25 +02:00
Yoan Lecoq 81aa6dbe48 Revert impl for Checked and Saturating 2017-04-30 08:29:21 +02:00
Yoan Lecoq 760604361d Add missing #[inline] hints 2017-04-29 08:35:37 +02:00
Yoan Lecoq 47b8c7b5ae impl Wrapping ops for Wrapping<T> 2017-04-29 08:29:02 +02:00
Yoan Lecoq 9c3e9791d2 impl Checked* and Saturating for Wrapping<T> 2017-04-29 08:22:44 +02:00
Yoan Lecoq f249edf546 impl ToPrimitive, FromPrimitive and NumCast for Wrapping<T> 2017-04-29 08:04:59 +02:00
Yoan Lecoq 35a9bcba19 impl Bounded for Wrapping<T> 2017-04-29 07:51:04 +02:00
Yoan Lecoq b2d957fe4b Small fix for older Rust versions 2017-04-29 07:47:39 +02:00
Yoan Lecoq 579466d95c impl PrimInt for Wrapping<T> 2017-04-29 07:46:51 +02:00
Yoan Lecoq 5b126673aa impl Signed and Unsigned for Wrapping<T> 2017-04-29 07:21:14 +02:00
Patrick Jackson 71a15212a1 Replace deprecated SipHasher. 2017-04-28 18:48:50 -07:00
Homu e2ea246016 Auto merge of #279 - yoanlcq:impl-num-for-wrapping, r=cuviper
Implemented Zero, One and Num for std::num::Wrapping<T>

Attempts to fix issue #278
2017-04-22 02:18:42 +09:00
Yoan Lecoq 2172a9368b impl One for Wrapping doesn't require Add 2017-04-21 19:10:42 +02:00
Yoan Lecoq 356a4ba5b5 Removed useless trait bounds 2017-04-21 18:56:23 +02:00
Yoan Lecoq b562c1ec39 Minor changes for correctness 2017-04-21 18:47:42 +02:00
Yoan Lecoq 9b06d4a0bb Attempt at fixing E0411 on older rust versions 2017-04-21 10:31:29 +02:00
Yoan Lecoq b024e1c326 Implemented Zero, One and Num for Wrapping<T> 2017-04-21 09:26:53 +02:00
Josh Stone 6513a5618b num-integer-0.1.34 2017-04-09 06:22:05 -07:00
Josh Stone fca95eaf42 num-complex-0.1.37 2017-04-09 06:18:09 -07:00
Homu aff06286ad Auto merge of #275 - bluss:repr-c, r=cuviper
Complex: Use repr(C) and add documentation for what it means

Here's an ambitious proposal that puts currently practiced ffi usage of `Complex<f32/f64>` on sound footing.

Fixes  #79

Current users appear to be:

- https://crates.io/crates/blas
  + Their use is not about Complex<f64> in an extern function's signature, but it is explicitly using that it is memory layout compatible.
2017-04-05 01:53:14 +09:00
bluss 0cf3419b9e complex: Use repr(C) and add documentation for what it means 2017-04-04 06:48:35 +02:00
Homu f63c933737 Auto merge of #272 - vks:binomial-coeffs, r=cuviper
Implement an iterator over the binomial coefficients

I'm not very happy with the excessive cloning, but to fix it the bounds on the type parameters would have to be excessive. We probably need something like [this](https://github.com/vks/discrete-log/blob/master/src/main.rs#L90) in `num-traits`.
2017-03-31 10:29:14 +09:00
Vinzent Steinberg 0fc6cb15a5 binomial: Discuss overflow 2017-03-29 14:13:39 +02:00
Vinzent Steinberg a7b459c05e Make `binomial` and `IterBinomial` less likely to overflow 2017-03-26 15:57:25 +02:00
Homu 4fc1e28832 Auto merge of #271 - vks:multinomial, r=cuviper
Implement multinomial
2017-03-26 04:40:20 +09:00
Homu 904d9b494f Auto merge of #170 - DonSheddow:complex-fmt, r=cuviper
Add formatting options for Complex

This adds LowerExp and UpperExp traits for Complex, taking precision into account. Fixes #148
2017-03-26 04:31:24 +09:00
Sigurd Kolltveit 2784b89837 Remove support for zero padding 2017-03-20 19:04:17 +01:00
Vinzent Steinberg d4deba6947 IterBinomial: Make tests closer to overflow threshold (like for binomial) 2017-03-20 10:45:27 +01:00