Skip to content

Commit

Permalink
Merge pull request #130 from cuviper/release-0.4.2
Browse files Browse the repository at this point in the history
Release 0.4.2
  • Loading branch information
cuviper authored May 8, 2024
2 parents fef7db2 + d4102c7 commit 4d55ad2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ categories = ["algorithms", "data-structures", "science", "no-std"]
license = "MIT OR Apache-2.0"
name = "num-rational"
repository = "https://github.com/rust-num/num-rational"
version = "0.4.1"
version = "0.4.2"
readme = "README.md"
exclude = ["/ci/*", "/.github/*"]
edition = "2021"
Expand Down
14 changes: 14 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Release 0.4.2 (2024-05-07)

- [Upgrade to 2021 edition, **MSRV 1.60**][126]
- [Add `Ratio::approximate_float_unsigned` to convert `FloatCore` types to unsigned][109]
- [Add `const ZERO` and `ONE`, and implement `num_traits::ConstZero` and `ConstOne`][128]
- [Add `Ratio::into_raw` to deconstruct the numerator and denominator][129]

**Contributors**: @cuviper, @Enyium, @flavioroth, @waywardmonkeys

[109]: https://github.com/rust-num/num-rational/pull/109
[126]: https://github.com/rust-num/num-rational/pull/126
[128]: https://github.com/rust-num/num-rational/pull/128
[129]: https://github.com/rust-num/num-rational/pull/129

# Release 0.4.1 (2022-06-23)

- [Fewer `clone` calls are used when reducing a new `Ratio<T>`][98].
Expand Down
20 changes: 7 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
// Ratio ops often use other "suspicious" ops
#![allow(clippy::suspicious_arithmetic_impl)]
#![allow(clippy::suspicious_op_assign_impl)]
// These use stdlib features higher than the MSRV
#![allow(clippy::manual_strip)] // 1.45
#![allow(clippy::manual_range_contains)] // 1.35

#[cfg(feature = "std")]
#[macro_use]
Expand Down Expand Up @@ -1068,15 +1065,11 @@ macro_rules! impl_formatting {
format!(concat!($fmt_str, "/", $fmt_str), self.numer, self.denom)
}
};
// TODO: replace with strip_prefix, when stabilized
let (pre_pad, non_negative) = {
if pre_pad.starts_with("-") {
(&pre_pad[1..], false)
} else {
(&pre_pad[..], true)
}
};
f.pad_integral(non_negative, $prefix, pre_pad)
if let Some(pre_pad) = pre_pad.strip_prefix("-") {
f.pad_integral(false, $prefix, pre_pad)
} else {
f.pad_integral(true, $prefix, &pre_pad)
}
}
#[cfg(not(feature = "std"))]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Expand Down Expand Up @@ -1585,7 +1578,8 @@ fn ratio_to_f64<T: Bits + Clone + Integer + Signed + ShlAssign<usize> + ToPrimit
// FPU do the job is faster and easier. In any other case, converting to f64s may lead
// to an inexact result: https://stackoverflow.com/questions/56641441/.
if let (Some(n), Some(d)) = (numer.to_i64(), denom.to_i64()) {
if MIN_EXACT_INT <= n && n <= MAX_EXACT_INT && MIN_EXACT_INT <= d && d <= MAX_EXACT_INT {
let exact = MIN_EXACT_INT..=MAX_EXACT_INT;
if exact.contains(&n) && exact.contains(&d) {
return n.to_f64().unwrap() / d.to_f64().unwrap();
}
}
Expand Down

0 comments on commit 4d55ad2

Please sign in to comment.