Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from rust-num:master #8

Open
wants to merge 216 commits into
base: master
Choose a base branch
from
Open
Changes from 4 commits
Commits
Show all changes
216 commits
Select commit Hold shift + click to select a range
ad583c2
Add the full circle constant τ.
m-ou-se Nov 26, 2019
ea47252
Add the π symbol to the doc comment of PI.
m-ou-se Nov 26, 2019
6e66f2d
Provide a default implementation for FloatConst::TAU.
m-ou-se Dec 6, 2019
77709dd
Merge #145
bors[bot] Dec 7, 2019
0cfe1ff
Update to autocfg 1
cuviper Jan 9, 2020
b0dde80
Merge #148
bors[bot] Jan 9, 2020
ef65ed6
Release 0.2.11
cuviper Jan 10, 2020
93ff6dc
Merge #149
bors[bot] Jan 10, 2020
54c9c25
wrapping: add WrappingNeg trait
ocstl Feb 10, 2020
a883d87
wrapping: remove some WrappingNeg tests
ocstl Feb 10, 2020
f94f9ce
Removed repeated words
vallentin Feb 11, 2020
2cf19ca
Merge #154
bors[bot] Feb 22, 2020
803f755
Fix the parameter name in the FloatCore::max example
cuviper Mar 6, 2020
ea2ff8d
Merge #158
bors[bot] Mar 6, 2020
e1ecc9d
Expand the WrappingNeg examples a little
cuviper Mar 6, 2020
1eb80e1
Merge #153
bors[bot] Mar 6, 2020
3488be2
Switch CI to GitHub Actions
cuviper Apr 10, 2020
71caa9c
Merge #160
bors[bot] Apr 10, 2020
4bac047
Linkify the MSRV and CI badges
cuviper Apr 18, 2020
a91bb7b
Use {float}::to_int_unchecked() in Rust 1.44+
cuviper Apr 20, 2020
052e765
Add saturating_mul() and refactor Saturating into subtraits. Fixes #40.
trepetti Apr 30, 2020
964752f
Fix formatting for SaturatingAdd, SaturatingMul and SaturatingSub tra…
trepetti Apr 30, 2020
86c3126
Restore and deprecate Saturating trait. Fix up doc strings for Satura…
trepetti May 2, 2020
cf16338
Merge #162
bors[bot] Jun 1, 2020
e9fcdb0
Add FloatConst::{LOG10_2, LOG2_10}
cuviper Jun 2, 2020
5f00e22
remove an unused pattern from saturating_impl
cuviper Jun 11, 2020
9d54f39
Merge #165 #171
bors[bot] Jun 11, 2020
fb10fe9
Release 0.2.12
cuviper Jun 11, 2020
f6852e0
Merge #172
bors[bot] Jun 11, 2020
1478326
add license terms to README
newpavlov Jun 18, 2020
4090814
#175 document cast traits about precision loss
Enet4 Jul 5, 2020
3973bab
Merge #176
bors[bot] Jul 7, 2020
ae63b9e
Add Overflowing trait
Jul 17, 2020
bdf0c1d
Remove std dep from integer MAX, MIN
Jul 17, 2020
7d26cec
update AsPrimitive Safety docs for rust 1.45
martin-t Jul 30, 2020
76cfbd1
Merge #173
bors[bot] Aug 19, 2020
652e420
remove example which was never UB from AsPrimitive docs
martin-t Aug 21, 2020
3196236
Merge #184
bors[bot] Aug 24, 2020
0ff6935
Trust the "i128" feature
cuviper Aug 27, 2020
234e855
Allow large f64-to-f32 to saturate to infinity
cuviper Aug 28, 2020
6c499ad
Normalize the comment style
cuviper Oct 6, 2020
a939c51
Correct docs for overflowing docs
Oct 24, 2020
26c9ad2
Merge #180
bors[bot] Oct 29, 2020
f0a980b
Merge #185 #186 #190
bors[bot] Oct 29, 2020
37e7658
Release 0.2.13
cuviper Oct 29, 2020
5b62992
Document relaxed requirements for Num::from_str_radix
cuviper Oct 29, 2020
5e3352c
Update the names for overflowing results
cuviper Oct 29, 2020
deedb93
Merge #193
bors[bot] Oct 29, 2020
e8da6fe
Release 0.2.14
cuviper Oct 29, 2020
06fe1e5
Use libm in Float::{min,max} and in FloatCore
cuviper Nov 14, 2020
e003ff4
use standard library for float from_str_radix with radix 10
tspiteri Feb 5, 2021
e71d7a9
match standard library float parsing of "-NaN"
tspiteri Feb 5, 2021
9c6f148
PrimInt: add reverse_bits() method
Xiretza Feb 12, 2021
9c8f20e
Merge #201
bors[bot] Mar 1, 2021
47d6922
Merge #196
bors[bot] Mar 2, 2021
502426f
PrimInt: add fallback for reverse_bits on rustc<1.37
Xiretza Feb 26, 2021
f9422e7
Add LowerBounded/UpperBounded traits
clarfonthey Mar 22, 2021
5cedc10
update readme for rust 2018 edition
ibraheemdev Mar 24, 2021
d134b8c
Merge #211
bors[bot] Apr 10, 2021
305532d
Merge #210
bors[bot] Apr 10, 2021
41a702c
Add leading_ones and trailing_ones to PrimInt
clarfonthey Mar 14, 2021
94761f7
PrimInt: add unit tests for reverse_bits
Xiretza Apr 13, 2021
cd877fe
Ignore case for float parsing of text special values
tspiteri Apr 15, 2021
93df4ad
Merge #205
bors[bot] Jun 15, 2021
ee28ebb
Merge #214
bors[bot] Jun 16, 2021
4ca742a
Merge branch 'master' into reverse-bits
cuviper Jun 16, 2021
92298b2
Merge #202
bors[bot] Jun 16, 2021
59a1753
Implement is_sign_* and signum methods in terms of libm.
ElectronicRU Jun 24, 2021
cfab8ed
Reimplement is_sign_negative as a bitcast, libm not necessary.
ElectronicRU Jun 30, 2021
96a89e6
Merge #218
bors[bot] Jul 8, 2021
c59999d
Fix cfg typo
alion02 Jan 21, 2022
ccd5bbf
Merge #231
bors[bot] Apr 29, 2022
136080b
impl Num Wrapping<T> can rely on NumOps instead
sshilovsky Feb 12, 2021
42e3f95
add test: check_numassignref_ops
sshilovsky Feb 12, 2021
53cbc45
Highlight difference in traits' abstraction level
sshilovsky Feb 12, 2021
6959b8a
Skip check_numassignref_ops test for old rustc
sshilovsky Feb 12, 2021
4b0e9bf
Merge #203
bors[bot] Apr 30, 2022
1ea0c35
Add support for euclidean division and modulation
SparrowLii Nov 13, 2020
87811d7
fixes float::Float and fmt
SparrowLii Nov 13, 2020
3672ce5
fixes ::Float
SparrowLii Nov 13, 2020
e7c3bcb
fixes example
SparrowLii Nov 13, 2020
4ad77d6
Fixes use core::float
SparrowLii Nov 13, 2020
2d761d4
fixes method impl
SparrowLii Nov 13, 2020
b29d99b
Fixes methods
SparrowLii Nov 13, 2020
c49f511
fixes MIN
SparrowLii Nov 13, 2020
ee53faf
Fixes epsilon
SparrowLii Nov 13, 2020
50afb16
fixes codes structure etc.
SparrowLii Nov 16, 2020
9c5034c
take references as parameters
SparrowLii Mar 2, 2021
7861645
tweak euclid tests
cuviper Apr 30, 2022
18575c2
Forward euclid methods when possible
cuviper Apr 30, 2022
4cd097c
Merge #195
bors[bot] Apr 30, 2022
64db6c3
Add copysign
XAMPPRocky Mar 17, 2021
7ca2456
Update float.rs
XAMPPRocky Oct 28, 2021
cabfb0b
Update float.rs
XAMPPRocky Oct 28, 2021
70b5c57
Update float.rs
XAMPPRocky Oct 28, 2021
30f8d3a
Make sure test_copysignf uses Float
cuviper Apr 30, 2022
3007712
Don't use an explicit copysign feature
cuviper Apr 30, 2022
e4e52de
Fix copysign tests for 1.8.0
cuviper Apr 30, 2022
edb4821
Merge #207
bors[bot] May 2, 2022
4a2e648
Release 0.2.15
cuviper May 3, 2022
1597c1c
Merge #236
bors[bot] May 3, 2022
3057196
Update to actions/checkout@v3
cuviper Jul 14, 2022
8e6e051
Switch from actions-rs/toolchain to dtolnay/rust-toolchain
cuviper Jul 14, 2022
42b3653
Switch from actions-rs/cargo to plain run
cuviper Jul 14, 2022
4d559f7
Stop explicitly naming CI steps
cuviper Jul 14, 2022
6d50d5d
Merge #242
bors[bot] Jul 14, 2022
da2bd55
Upgrade to 2018 edition
cuviper May 3, 2022
e7fdddb
Update MSRV to 1.31
cuviper May 3, 2022
4fc497f
Assume i128 support
cuviper May 3, 2022
b95b3fd
Always test libm support
cuviper May 3, 2022
856d342
Always test NumAssignRef
cuviper May 3, 2022
f3383ea
Update CI test versions
cuviper May 3, 2022
1010ba9
Remove useless extern crate
cuviper May 3, 2022
a933de0
Test NaN is_sign_positive/negative
cuviper May 3, 2022
fd601a8
Use {float}::to_bits instead of mem::transmute
cuviper May 3, 2022
1ffb516
Always test to_degrees_rounding
cuviper May 3, 2022
8bfc601
test Neg for Wrapping
cuviper May 3, 2022
3392377
Remove outdated optry! macro
cuviper May 3, 2022
a8812c1
Fix clippy::assign_op_pattern
cuviper May 3, 2022
b87abdc
Fix clippy::manual_map
cuviper May 3, 2022
a5bad70
Fix clippy::collapsible_else_if
cuviper May 3, 2022
5397a1c
Merge #240
bors[bot] Jul 14, 2022
df7d933
ci: downgrade libm for MSRV testing
cuviper Feb 10, 2023
7daa55e
ci: workaround for git zlib stream error
cuviper Feb 10, 2023
b5906ee
Merge #257
bors[bot] Feb 10, 2023
7cc8d46
Allow `arithmetic_overflow` lint in a cast test
cuviper Apr 12, 2023
8ba2458
Merge #267
bors[bot] Apr 12, 2023
789b6b5
Make CheckedShr and CheckedShl documentation more consistent
vicsn May 19, 2023
4ac94b4
Merge #270
bors[bot] May 22, 2023
316bdf0
Clarify mul_add docs
rs017991 Jul 3, 2023
d3b0c12
Clarify mul_add docs: No Pseudocode
rs017991 Jul 7, 2023
f4db632
Merge #275
bors[bot] Jul 11, 2023
878df73
Add `--generate-link-to-definition` option when building on docs.rs
GuillaumeGomez Jul 14, 2023
85edb5e
Merge #277
bors[bot] Jul 20, 2023
9d85e9e
+Float::is_subnormal
ctrlcctrlv Mar 28, 2023
22509ff
Add tests for is_subnormal()
ctrlcctrlv Mar 28, 2023
19cb6f0
Add a default impl for `Float::is_subnormal`
cuviper Jul 20, 2023
f5dc702
Check the existence of is_subnormal (1.53) before forwarding
cuviper Jul 20, 2023
90b8981
Simplify is_subnormal tests
cuviper Jul 20, 2023
58b46b1
Fix is_subnormal doc tests
cuviper Jul 20, 2023
c263032
Merge #279
bors[bot] Jul 20, 2023
4f08176
Update Float forwarding for MSRV 1.31
cuviper Jul 20, 2023
13cd223
Merge #280
bors[bot] Jul 20, 2023
2ecd420
Convert between int and bytes
kaidokert Oct 22, 2022
e566d77
Simplify float to/from_bytes and enable tests
kaidokert Oct 25, 2022
447e05d
has_i128 is always assumed now
cuviper Feb 10, 2023
2505954
Split ToFrom to separate To and From traits
kaidokert Feb 26, 2023
001dd32
Fix the `cfg` attributes for bytes
cuviper Apr 12, 2023
29b89c3
Add default impls of to/from_ne_bytes
cuviper Apr 13, 2023
e402e20
Remove the unnecessary $I in float bytes
cuviper Apr 13, 2023
c89a430
Clean up bytes examples
cuviper Apr 13, 2023
bbeeaa2
Allow FromBytes::Bytes to be unsized
cuviper Apr 13, 2023
4195ddf
Merge #224
bors[bot] Jul 20, 2023
0e57dba
Release 0.2.16
cuviper Jul 20, 2023
c2de8be
Merge #281
bors[bot] Jul 20, 2023
d9d94f8
Bugfix for text codeblock in documentation.
robamu Sep 18, 2023
ef36d69
Merge #286
bors[bot] Sep 18, 2023
34e309a
Release 0.2.17
cuviper Oct 7, 2023
0a27d8c
Merge #289
bors[bot] Oct 7, 2023
a135b11
feat: add an extra method to (Checked)Euclid trait to get both quotie…
tdelabro Oct 12, 2023
3def73d
typos, doc and naming
tdelabro Oct 13, 2023
8971fb6
ci: Update to `actions/checkout@v4`.
waywardmonkeys Oct 19, 2023
df7b60d
put back code deleted by mistake
tdelabro Oct 19, 2023
2f00cfa
`TotalOrder` trait for floating point numbers
andrewjradcliffe Oct 23, 2023
d916787
Merge #292
bors[bot] Oct 25, 2023
8175e12
Fix spelling of "overridden"
cuviper Oct 25, 2023
f832428
Merge #291
bors[bot] Oct 25, 2023
2a76a8d
Limit exposure
andrewjradcliffe Oct 26, 2023
621b1b7
Use Ordering from core where appropriate
cuviper Oct 26, 2023
ec24ea2
Use {float}::from_bits instead of mem::transmute
cuviper Oct 26, 2023
a4c9435
The total_cmp tests don't need Float
cuviper Oct 26, 2023
d664758
Backport total_cmp for Rust <1.62
cuviper Oct 26, 2023
56210ef
Add CI for Rust 1.62 has_total_cmp
cuviper Oct 26, 2023
aeee038
Skip signaling NaN tests on x86
cuviper Oct 27, 2023
61d9a1b
Merge #295
bors[bot] Oct 27, 2023
a8ec422
Switch from bors to merge queues
cuviper Feb 1, 2024
fbd56f1
Merge pull request #306 from cuviper/ci-merge
cuviper Feb 1, 2024
3a68b13
Make the CI status more robust
cuviper Feb 1, 2024
46392d7
Merge pull request #307 from cuviper/ci-merge
cuviper Feb 1, 2024
d53f3f2
ci: Use a single action to collect final status
cuviper Feb 6, 2024
82616cb
ci: Add a registry cache for git protocol
cuviper Feb 6, 2024
29c5b46
Merge pull request #308 from cuviper/ci
cuviper Feb 6, 2024
06c0ee0
Add `ZeroConstant` and `OneConstant` traits
tarcieri Dec 14, 2023
536dcf2
Remove blanket impls; add impls for `Wrapping`
tarcieri Dec 17, 2023
bc42b83
Rename to ConstZero/ConstOne and re-export from toplevel
tarcieri Dec 30, 2023
e48ffe2
Update src/identities.rs
tarcieri Dec 31, 2023
6ab6de2
Update src/identities.rs
tarcieri Dec 31, 2023
67d9e74
Avoid `Self` constructor for `Wrapping`
cuviper Feb 8, 2024
a095b70
Merge pull request #303 from tarcieri/constant-traits
cuviper Feb 8, 2024
5c2cc9b
Release 0.2.18
cuviper Feb 8, 2024
eb20b40
Merge pull request #309 from cuviper/release-0.2.18
cuviper Feb 8, 2024
e4609ed
Use namespaced-features to safely bump to MSRV 1.60
cuviper Feb 7, 2024
3b74d01
Assume has_to_int_unchecked
cuviper Feb 7, 2024
2c012d5
Assume has_reverse_bits
cuviper Feb 7, 2024
8a59e17
Assume has_leading_trailing_ones
cuviper Feb 7, 2024
84e935b
Assume has_div_euclid
cuviper Feb 8, 2024
7c2f3bc
Assume has_copysign
cuviper Feb 8, 2024
33c92de
Assume has_is_subnormal
cuviper Feb 8, 2024
531d965
Note the MSRV for total_cmp
cuviper Feb 8, 2024
7212041
Assume has_int_to_from_bytes
cuviper Feb 8, 2024
4e253cd
Assume has_float_to_from_bytes
cuviper Feb 8, 2024
e9bea92
Upgrade to 2021 edition
cuviper Feb 8, 2024
ca42b4e
Update the MSRV in docs
cuviper Feb 8, 2024
a90d4a6
Merge pull request #310 from cuviper/msrv-1.60
cuviper Mar 25, 2024
2957044
Implementing clamp for Float trait
michaelciraci Jan 19, 2024
1a44ffb
Add a default impl for `Float::clamp`
cuviper May 3, 2024
8358949
Merge pull request #305 from michaelciraci/implement-float-clamp
cuviper May 3, 2024
1a8d429
Release 0.2.19
cuviper May 3, 2024
7ec3d41
Merge pull request #321 from cuviper/release-0.2.19
cuviper May 3, 2024
c477dfe
Fix bug in example for trait method `Float::integer_decode`
mtilda Jun 26, 2024
d3935bf
Change value of `num` in example for trait method `Float::integer_dec…
mtilda Jun 26, 2024
e8c766f
Refactor `2_f32.powf(exponent)` as `exponent_f.exp2()`
mtilda Jun 27, 2024
b1f3bda
Merge pull request #326 from mtilda/mtilda/patch/fix-example-for-floa…
cuviper Jun 27, 2024
e92f633
Fix checked operations documentation.
ocstl Jul 26, 2024
e8cb7b0
Fix checked operations documentation.
ocstl Jul 27, 2024
022f250
Merge pull request #332 from ocstl/master
cuviper Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -43,7 +43,9 @@ pub use ops::checked::{
pub use ops::inv::Inv;
pub use ops::mul_add::{MulAdd, MulAddAssign};
pub use ops::saturating::Saturating;
pub use ops::wrapping::{WrappingAdd, WrappingMul, WrappingShl, WrappingShr, WrappingSub};
pub use ops::wrapping::{
WrappingAdd, WrappingMul, WrappingNeg, WrappingShl, WrappingShr, WrappingSub,
};
pub use pow::{checked_pow, pow, Pow};
pub use sign::{abs, abs_sub, signum, Signed, Unsigned};

67 changes: 66 additions & 1 deletion src/ops/wrapping.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::num::Wrapping;
use core::ops::{Add, Mul, Shl, Shr, Sub};
use core::ops::{Add, Mul, Neg, Shl, Shr, Sub};

macro_rules! wrapping_impl {
($trait_name:ident, $method:ident, $t:ty) => {
@@ -89,6 +89,54 @@ wrapping_impl!(WrappingMul, wrapping_mul, isize);
#[cfg(has_i128)]
wrapping_impl!(WrappingMul, wrapping_mul, i128);

macro_rules! wrapping_unary_impl {
($trait_name:ident, $method:ident, $t:ty) => {
impl $trait_name for $t {
#[inline]
fn $method(&self) -> $t {
<$t>::$method(*self)
}
}
};
}

/// Performs a negation that does not panic.
pub trait WrappingNeg: Sized {
/// Wrapping (modular) negation. Computes `-self`,
/// wrapping around at the boundary of the type.
///
/// Since unsigned types do not have negative equivalents
/// all applications of this function will wrap (except for `-0`).
/// For values smaller than the corresponding signed type's maximum
/// the result is the same as casting the corresponding signed value.
/// Any larger values are equivalent to `MAX + 1 - (val - MAX - 1)` where
/// `MAX` is the corresponding signed type's maximum.
///
/// ```
/// use num_traits::WrappingNeg;
///
/// assert_eq!(100i8.wrapping_neg(), -100);
/// assert_eq!((-100i8).wrapping_neg(), 100);
/// assert_eq!((-128i8).wrapping_neg(), -128); // wrapped!
/// ```
fn wrapping_neg(&self) -> Self;
}

wrapping_unary_impl!(WrappingNeg, wrapping_neg, u8);
wrapping_unary_impl!(WrappingNeg, wrapping_neg, u16);
wrapping_unary_impl!(WrappingNeg, wrapping_neg, u32);
wrapping_unary_impl!(WrappingNeg, wrapping_neg, u64);
wrapping_unary_impl!(WrappingNeg, wrapping_neg, usize);
#[cfg(has_i128)]
wrapping_unary_impl!(WrappingNeg, wrapping_neg, u128);
wrapping_unary_impl!(WrappingNeg, wrapping_neg, i8);
wrapping_unary_impl!(WrappingNeg, wrapping_neg, i16);
wrapping_unary_impl!(WrappingNeg, wrapping_neg, i32);
wrapping_unary_impl!(WrappingNeg, wrapping_neg, i64);
wrapping_unary_impl!(WrappingNeg, wrapping_neg, isize);
#[cfg(has_i128)]
wrapping_unary_impl!(WrappingNeg, wrapping_neg, i128);

macro_rules! wrapping_shift_impl {
($trait_name:ident, $method:ident, $t:ty) => {
impl $trait_name for $t {
@@ -195,6 +243,14 @@ where
Wrapping(self.0.wrapping_mul(&v.0))
}
}
impl<T: WrappingNeg> WrappingNeg for Wrapping<T>
where
Wrapping<T>: Neg<Output = Wrapping<T>>,
{
fn wrapping_neg(&self) -> Self {
Wrapping(self.0.wrapping_neg())
}
}
impl<T: WrappingShl> WrappingShl for Wrapping<T>
where
Wrapping<T>: Shl<usize, Output = Wrapping<T>>,
@@ -223,6 +279,9 @@ fn test_wrapping_traits() {
fn wrapping_mul<T: WrappingMul>(a: T, b: T) -> T {
a.wrapping_mul(&b)
}
fn wrapping_neg<T: WrappingNeg>(a: T) -> T {
a.wrapping_neg()
}
fn wrapping_shl<T: WrappingShl>(a: T, b: u32) -> T {
a.wrapping_shl(b)
}
@@ -232,11 +291,14 @@ fn test_wrapping_traits() {
assert_eq!(wrapping_add(255, 1), 0u8);
assert_eq!(wrapping_sub(0, 1), 255u8);
assert_eq!(wrapping_mul(255, 2), 254u8);
assert_eq!(wrapping_neg(255), 1u8);
assert_eq!(wrapping_shl(255, 8), 255u8);
assert_eq!(wrapping_shr(255, 8), 255u8);
assert_eq!(wrapping_add(255, 1), (Wrapping(255u8) + Wrapping(1u8)).0);
assert_eq!(wrapping_sub(0, 1), (Wrapping(0u8) - Wrapping(1u8)).0);
assert_eq!(wrapping_mul(255, 2), (Wrapping(255u8) * Wrapping(2u8)).0);
// TODO: Test for Wrapping::Neg. Not possible yet since core::ops::Neg was
// only added to core::num::Wrapping<_> in Rust 1.10.
assert_eq!(wrapping_shl(255, 8), (Wrapping(255u8) << 8).0);
assert_eq!(wrapping_shr(255, 8), (Wrapping(255u8) >> 8).0);
}
@@ -259,6 +321,9 @@ fn wrapping_is_wrappingmul() {
require_wrappingmul(&Wrapping(42));
}

// TODO: Test for Wrapping::Neg. Not possible yet since core::ops::Neg was
// only added to core::num::Wrapping<_> in Rust 1.10.

#[test]
fn wrapping_is_wrappingshl() {
fn require_wrappingshl<T: WrappingShl>(_: &T) {}