Commit Graph

740 Commits

Author SHA1 Message Date
Toshiki Teramura ffa67c8527 CI typo fix 2018-02-01 11:56:13 -08:00
Josh Stone 67f03391a1 Bump to 0.2 for the breaking feature change 2018-01-31 16:19:00 -08:00
Josh Stone 36b2514f4b Note the std feature in README.md 2018-01-31 16:16:41 -08:00
Josh Stone 4fbc583eb9 Don't use wildcards for pub use 2018-01-31 16:05:43 -08:00
Josh Stone 79786ac518 test no_std in CI 2018-01-31 15:56:25 -08:00
Josh Stone e6bb97b3ac Make `Float` and `Real` depend on the `std` feature
We don't have implementations for many of the methods in `no_std`.  It's
hostile to external implementors if some trait methods are conditional
on a feature, as that feature could be added by anyone in a dependency
tree.  Instead, let's just live without these traits for now.
2018-01-31 15:56:06 -08:00
Vinzent Steinberg a843027b56 Re-introduce the std feature
This is a port of @vks's rust-num/num#296, but without the feature-
toggled changes to `Float`.
2018-01-31 15:42:55 -08:00
bors[bot] 3716330128 Merge #27
27: Release num-traits 0.1.42 r=cuviper a=cuviper
2018-01-23 02:12:39 +00:00
Josh Stone ff73e62d93 Release num-traits 0.1.42 2018-01-22 18:06:22 -08:00
bors[bot] 93be5dbff2 Merge #23
23: Add RealNum trait for real data types (Float, but without floating-point specific features) r=cuviper a=yoanlcq

This is supposed to fix [#19](https://github.com/rust-num/num-traits/issues/19); I assumed going ahead would be better than bumping the thread.  

In any case, I understand that it is a quite significant addition and won't mind too much if it doesn't make it.

This adds a new `RealNum` trait, along with a universal impl `impl<T: Float> RealNum for T { ... }`.  
Therefore, this shouldn't be a breaking change, except in places where both traits are imported (which obviously only happened in a few places in this crate).

The intent is that generic code may prefer to use `RealNum` instead of `Float` when floating-point isn't a requirement. In the future (next major version ?), I guess `Float` could be made to only provide floating-point-specific features on top of `RealNum`.

Most of the code+doc was copy-pasted from `Float`, but the doc comments should be up-to-date with the situation; `Float` only makes an appearance when talking about NaN and infinity.

Issues I've seen : 
- `RealNum` might not be the name we want;
- I've mentioned that `sqrt()` is allowed to panic if the input is negative and has no meaningful NaN representation;
- Should we do that too for e.g `log()` ? Like `sqrt()`, it's supposed to return Nan when `x < 0`.

Thanks for your time. :)
2018-01-19 01:39:13 +00:00
Yoan Lecoq 1e892e2238 Remove legacy default implementations 2018-01-18 21:32:46 +01:00
Yoan Lecoq a2337f392b Document panic cases where T doesn't support NaN 2018-01-18 08:44:05 +01:00
bors[bot] aa7c15e0e9 Merge #17 #21
17: Add AsPrimitive trait for generic casting with `as` r=cuviper a=Enet4

This is my personal attempt at #7. It is fairly similar to what can be found in `asprim`, although implemented from scratch. Please let me know of what you think. Could it use more tests? Should I also leave a safety notice that some conversions with `as` are currently UB (rust-lang/rust#10184)? 


21: Add checked shifts r=cuviper a=fabianschuiki

Add traits `CheckedShl` and `CheckedShr` that correspond to the standard
library's `checked_shl` and `checked_shr` functions. Implement the trait
on all primitive integer types by default, akin to what the standard
library does.

The stdlib is somewhat inconsistent when it comes to the type of the
shift amount. The `checked_*` functions have a `u32` shift amount, but
the `std::ops::{Shl,Shr}` traits are generic over the shift amount. Also
the stdlib implements these traits for all primitive integer types as
right-hand sides. Our implementation mimics this behaviour.
2018-01-18 05:37:47 +00:00
Eduardo Pinho 31218add95 Include note for implementers of AsPrimitive 2018-01-14 21:23:19 +00:00
Fabian Schuiki 809ccff63f Fix checked shift RHS to u32, drop from PrimInt
Make the checked left and right shifts take a `u32` as right-hand side,
which is more consistent with the other checked operations. Also drop
`CheckedShl` and `CheckedShr` from the `PrimInt` trait, to not break
existing code. Add doctests for the two traits.
2018-01-13 15:02:38 +01:00
bors[bot] 9c8676e6d5 Merge #22
22: Implement std::fmt::Display for ParseFloatError r=cuviper a=svartalf

Basically it is a copy of the stdlib implementation, should close #2
2018-01-13 05:27:49 +00:00
Yoan Lecoq ddd664ae2b RealNum -> Real 2018-01-06 15:51:10 +01:00
Yoan Lecoq 52c87dd410 Remove 2018-01-05 10:01:29 +01:00
Yoan Lecoq 5a6997c1c8 Add RealNum trait 2018-01-05 09:06:23 +01:00
svartalf 53ab360d94 std::fmt::Display implemented for ParseFloatError 2018-01-04 16:46:02 +03:00
Fabian Schuiki 21dfae004c Add checked shifts
Add traits `CheckedShl` and `CheckedShr` that correspond to the standard
library's `checked_shl` and `checked_shr` functions. Implement the trait
on all primitive integer types by default, akin to what the standard
library does.

The stdlib is somewhat inconsistent when it comes to the type of the
shift amount. The `checked_*` functions have a `u32` shift amount, but
the `std::ops::{Shl,Shr}` traits are generic over the shift amount. Also
the stdlib implements these traits for all primitive integer types as
right-hand sides. Our implementation mimics this behaviour.
2018-01-03 16:25:13 +01:00
Eduardo Pinho af693fef48 Add safety notice in AsPrimitive docs 2017-12-21 21:03:25 +00:00
Eduardo Pinho 773a222237 Add conversions from `bool` in `AsPrimitive` 2017-12-20 21:41:45 +00:00
Eduardo Pinho 741e1f4e09 Add AsPrimitive trait, impls and tests 2017-12-20 00:05:36 +00:00
Josh Stone 42a610d323 Move num-traits to its own repo
All the prior `num` history is kept, so old `num-traits` tags are still
valid, but future development here will be just for `num-traits`.
2017-12-18 17:35:41 -08:00
bors[bot] f172ef3a6b Merge #350
350: Avoid large intermediate product in LCM r=cuviper a=mhogrefe

Changed the implementation of BigUint LCM from
`((self * other) / self.gcd(other))`
to
`self / self.gcd(other) * other`

The division is exact in both cases, so the result is the same, but the new code avoids the potentially-large intermediate product, speeding things up and using less memory.

I also removed the unnecessary parentheses, because I think it's clear what order everything will be executed in. But if others think differently I can add them back.
2017-12-14 08:07:15 +00:00
bors[bot] a0c431e270 Merge #351
351: Remove num-macros r=cuviper a=cuviper

The first commit gives a final deprecation bump to `num-macros`, and
the second removes it from the repo altogether.
2017-12-14 07:54:24 +00:00
Josh Stone d90ae0ae8b Remove num-macros 2017-12-13 23:44:49 -08:00
Josh Stone bd1701ded4 macros: bump to 0.1.40, deprecated 2017-12-13 23:41:50 -08:00
Mikhail Hogrefe 56a029b20f Avoid large intermediate product in LCM 2017-12-13 21:13:57 -05:00
Josh Stone c24f76781b num: bump to 0.1.41
Syncing the metacrate to the latest of all subcrates.
2017-12-01 13:31:33 -08:00
Josh Stone 98cb815183 bigint: bump to 0.1.41
- Now uses Toom-3 multiplication for large inputs.
- `BigInt`/`BigUint` parsing now accepts `_` separating digits.
- `BigInt`/`BigUint::assign_from_slice` reinitializes the value, keeping
  the same internal buffer.
- `BigUint` now implements many `*Assign` ops.
- `BigUint::modpow(exp, mod)` performs efficient modular exponentiation.
2017-12-01 13:15:22 -08:00
Josh Stone 18b48f335e complex: bump to 0.1.41
`Complex` now implements `Num`, `Rem`, and `RemAssign`.

(Complex remainders don't have a clear mathematical basis, but we choose
to round toward zero to a gaussian integer.)
2017-12-01 13:02:13 -08:00
Josh Stone 0e1c4c8b65 traits: bump to 0.1.41
minor warning fixes
2017-12-01 12:54:48 -08:00
bors[bot] 0e31f3c6b3 Merge #345
345: Downgrade libc for Rust 1.8 CI r=cuviper a=cuviper
2017-12-01 01:30:41 +00:00
Josh Stone a7464b2b42 Roll back libc in the ci scripts too 2017-11-30 17:01:09 -08:00
Josh Stone d354559365 Downgrade libc for Rust 1.8 CI 2017-11-30 16:15:45 -08:00
Josh Stone cc3be86781 rational: bump to 0.1.40 2017-11-08 14:40:10 -08:00
bors[bot] ca7e438d77 Merge #342
342: rational: check for NaN when approximating floats r=cuviper a=cuviper

We had a test for NaN already, but thanks to undefined casts (#119) it
was only passing by luck -- on armv7hl it failed:

https://bugzilla.redhat.com/show_bug.cgi?id=1511187

Now we check for NaN explicitly.
2017-11-08 22:29:38 +00:00
Josh Stone b67f1bd6d6 rational: check for NaN when approximating floats
We had a test for NaN already, but thanks to undefined casts (#119) it
was only passing by luck -- on armv7hl it failed:

     https://bugzilla.redhat.com/show_bug.cgi?id=1511187

Now we check for NaN explicitly.
2017-11-08 14:09:05 -08:00
bors[bot] a203e9f9fc Merge #339
339: Implement modpow() for BigUint backed by Montgomery Multiplication r=cuviper a=str4d

Based on this Gist: https://gist.github.com/yshui/027eecdf95248ea69606

Also adds support to `BigUint.from_str_radix()` for using `_` as a visual separator.

Closes #136
2017-11-02 19:37:52 +00:00
Josh Stone ed10d617b5 bigint: Add a modpow fallback for even modulus 2017-10-22 16:44:05 -07:00
Josh Stone 35b7187e83 bigint::monty: use infallible conversions in tests 2017-10-22 15:49:51 -07:00
Josh Stone bb0c9324b2 bigint::monty: deduplicate mr.n and mr.p 2017-10-22 15:45:01 -07:00
Josh Stone b380880ed3 bigint::monty: simplify modpow zero test 2017-10-22 15:38:50 -07:00
Josh Stone 96c4a26624 bigint::monty: simplify modpow parameter init 2017-10-22 15:37:48 -07:00
Josh Stone 7fa27b6007 bigint::monty: simplify redc return value 2017-10-22 15:36:33 -07:00
Josh Stone 5708db0f67 bigint::monty: simplify redc masks 2017-10-22 15:34:46 -07:00
Josh Stone 5a0de140c9 bigint::monty: use mac_digit 2017-10-22 15:30:17 -07:00
Josh Stone 4d35815426 bigint::monty: simplify work space allocation 2017-10-22 15:28:59 -07:00