Skip to content

Commit 4d55ad2

Browse files
authored
Merge pull request #130 from cuviper/release-0.4.2
Release 0.4.2
2 parents fef7db2 + d4102c7 commit 4d55ad2

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ categories = ["algorithms", "data-structures", "science", "no-std"]
88
license = "MIT OR Apache-2.0"
99
name = "num-rational"
1010
repository = "https://github.com/rust-num/num-rational"
11-
version = "0.4.1"
11+
version = "0.4.2"
1212
readme = "README.md"
1313
exclude = ["/ci/*", "/.github/*"]
1414
edition = "2021"

RELEASES.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Release 0.4.2 (2024-05-07)
2+
3+
- [Upgrade to 2021 edition, **MSRV 1.60**][126]
4+
- [Add `Ratio::approximate_float_unsigned` to convert `FloatCore` types to unsigned][109]
5+
- [Add `const ZERO` and `ONE`, and implement `num_traits::ConstZero` and `ConstOne`][128]
6+
- [Add `Ratio::into_raw` to deconstruct the numerator and denominator][129]
7+
8+
**Contributors**: @cuviper, @Enyium, @flavioroth, @waywardmonkeys
9+
10+
[109]: https://github.com/rust-num/num-rational/pull/109
11+
[126]: https://github.com/rust-num/num-rational/pull/126
12+
[128]: https://github.com/rust-num/num-rational/pull/128
13+
[129]: https://github.com/rust-num/num-rational/pull/129
14+
115
# Release 0.4.1 (2022-06-23)
216

317
- [Fewer `clone` calls are used when reducing a new `Ratio<T>`][98].

src/lib.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
// Ratio ops often use other "suspicious" ops
2020
#![allow(clippy::suspicious_arithmetic_impl)]
2121
#![allow(clippy::suspicious_op_assign_impl)]
22-
// These use stdlib features higher than the MSRV
23-
#![allow(clippy::manual_strip)] // 1.45
24-
#![allow(clippy::manual_range_contains)] // 1.35
2522

2623
#[cfg(feature = "std")]
2724
#[macro_use]
@@ -1068,15 +1065,11 @@ macro_rules! impl_formatting {
10681065
format!(concat!($fmt_str, "/", $fmt_str), self.numer, self.denom)
10691066
}
10701067
};
1071-
// TODO: replace with strip_prefix, when stabilized
1072-
let (pre_pad, non_negative) = {
1073-
if pre_pad.starts_with("-") {
1074-
(&pre_pad[1..], false)
1075-
} else {
1076-
(&pre_pad[..], true)
1077-
}
1078-
};
1079-
f.pad_integral(non_negative, $prefix, pre_pad)
1068+
if let Some(pre_pad) = pre_pad.strip_prefix("-") {
1069+
f.pad_integral(false, $prefix, pre_pad)
1070+
} else {
1071+
f.pad_integral(true, $prefix, &pre_pad)
1072+
}
10801073
}
10811074
#[cfg(not(feature = "std"))]
10821075
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
@@ -1585,7 +1578,8 @@ fn ratio_to_f64<T: Bits + Clone + Integer + Signed + ShlAssign<usize> + ToPrimit
15851578
// FPU do the job is faster and easier. In any other case, converting to f64s may lead
15861579
// to an inexact result: https://stackoverflow.com/questions/56641441/.
15871580
if let (Some(n), Some(d)) = (numer.to_i64(), denom.to_i64()) {
1588-
if MIN_EXACT_INT <= n && n <= MAX_EXACT_INT && MIN_EXACT_INT <= d && d <= MAX_EXACT_INT {
1581+
let exact = MIN_EXACT_INT..=MAX_EXACT_INT;
1582+
if exact.contains(&n) && exact.contains(&d) {
15891583
return n.to_f64().unwrap() / d.to_f64().unwrap();
15901584
}
15911585
}

0 commit comments

Comments
 (0)