Skip to content

Commit 3e80f42

Browse files
authored
Merge branch 'reem:master' into master
2 parents 6716dfb + 25da208 commit 3e80f42

File tree

6 files changed

+306
-31
lines changed

6 files changed

+306
-31
lines changed

.github/workflows/tests.yaml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,17 @@ jobs:
2222
rustup toolchain install ${{ matrix.rust }} --profile=minimal
2323
rustup override set ${{ matrix.rust }}
2424
25-
- name: Install rustfmt + clippy
26-
if: matrix.rust == 'stable'
27-
run: |
28-
# remove non-rustup-managed versions already present in default image
29-
rm -f /home/runner/.cargo/bin/{rustfmt,cargo-fmt}
30-
31-
rustup toolchain install ${{ matrix.rust }} --profile=minimal --component=clippy,rustfmt
32-
3325
- name: Check Fmt
3426
if: matrix.rust == 'stable'
35-
run: cargo fmt --check
27+
run: |
28+
rustup component add rustfmt
29+
cargo fmt --check
3630
3731
- name: Check Lints (all features)
3832
if: matrix.rust == 'stable'
39-
run: cargo clippy --tests --features ${{ env.all_features }}
33+
run: |
34+
rustup component add clippy
35+
cargo clippy --tests --features ${{ env.all_features }}
4036
4137
- name: Test (default features)
4238
run: cargo test

.travis.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ordered-float"
3-
version = "5.0.0"
3+
version = "5.1.0"
44
authors = [
55
"Jonathan Reem <[email protected]>",
66
"Matt Brubeck <[email protected]>",

src/lib.rs

Lines changed: 168 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use core::ops::{
2424
use core::str::FromStr;
2525

2626
pub use num_traits::float::FloatCore;
27+
#[cfg(any(feature = "std", feature = "libm"))]
28+
use num_traits::real::Real;
2729
use num_traits::{
2830
AsPrimitive, Bounded, FloatConst, FromPrimitive, Num, NumCast, One, Signed, ToPrimitive, Zero,
2931
};
@@ -1911,7 +1913,7 @@ impl<E: fmt::Debug + Error + 'static> Error for ParseNotNanError<E> {
19111913
impl<E: fmt::Display> fmt::Display for ParseNotNanError<E> {
19121914
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
19131915
match self {
1914-
ParseNotNanError::ParseFloatError(e) => write!(f, "Parse error: {}", e),
1916+
ParseNotNanError::ParseFloatError(e) => write!(f, "Parse error: {e}"),
19151917
ParseNotNanError::IsNaN => write!(f, "NotNan parser encounter a NaN"),
19161918
}
19171919
}
@@ -1957,6 +1959,170 @@ impl<T: FloatCore> NumCast for NotNan<T> {
19571959
}
19581960
}
19591961

1962+
#[cfg(any(feature = "std", feature = "libm"))]
1963+
impl<T: Real + FloatCore> Real for NotNan<T> {
1964+
fn min_value() -> Self {
1965+
NotNan(<T as Real>::min_value())
1966+
}
1967+
fn min_positive_value() -> Self {
1968+
NotNan(<T as Real>::min_positive_value())
1969+
}
1970+
fn epsilon() -> Self {
1971+
NotNan(Real::epsilon())
1972+
}
1973+
fn max_value() -> Self {
1974+
NotNan(<T as Real>::max_value())
1975+
}
1976+
fn floor(self) -> Self {
1977+
NotNan(Real::floor(self.0))
1978+
}
1979+
fn ceil(self) -> Self {
1980+
NotNan(Real::ceil(self.0))
1981+
}
1982+
fn round(self) -> Self {
1983+
NotNan(Real::round(self.0))
1984+
}
1985+
fn trunc(self) -> Self {
1986+
NotNan(Real::trunc(self.0))
1987+
}
1988+
fn fract(self) -> Self {
1989+
NotNan(Real::fract(self.0))
1990+
}
1991+
fn abs(self) -> Self {
1992+
NotNan(Real::abs(self.0))
1993+
}
1994+
fn signum(self) -> Self {
1995+
NotNan(Real::signum(self.0))
1996+
}
1997+
fn is_sign_positive(self) -> bool {
1998+
Real::is_sign_positive(self.0)
1999+
}
2000+
fn is_sign_negative(self) -> bool {
2001+
Real::is_sign_negative(self.0)
2002+
}
2003+
fn mul_add(self, a: Self, b: Self) -> Self {
2004+
NotNan(self.0.mul_add(a.0, b.0))
2005+
}
2006+
fn recip(self) -> Self {
2007+
NotNan(Real::recip(self.0))
2008+
}
2009+
fn powi(self, n: i32) -> Self {
2010+
NotNan(Real::powi(self.0, n))
2011+
}
2012+
fn powf(self, n: Self) -> Self {
2013+
// Panics if self < 0 and n is not an integer
2014+
NotNan::new(self.0.powf(n.0)).expect("Power resulted in NaN")
2015+
}
2016+
fn sqrt(self) -> Self {
2017+
// Panics if self < 0
2018+
NotNan::new(self.0.sqrt()).expect("Square root resulted in NaN")
2019+
}
2020+
fn exp(self) -> Self {
2021+
NotNan(self.0.exp())
2022+
}
2023+
fn exp2(self) -> Self {
2024+
NotNan(self.0.exp2())
2025+
}
2026+
fn ln(self) -> Self {
2027+
// Panics if self <= 0
2028+
NotNan::new(self.0.ln()).expect("Natural logarithm resulted in NaN")
2029+
}
2030+
fn log(self, base: Self) -> Self {
2031+
// Panics if self <= 0 or base <= 0
2032+
NotNan::new(self.0.log(base.0)).expect("Logarithm resulted in NaN")
2033+
}
2034+
fn log2(self) -> Self {
2035+
// Panics if self <= 0
2036+
NotNan::new(self.0.log2()).expect("Logarithm resulted in NaN")
2037+
}
2038+
fn log10(self) -> Self {
2039+
// Panics if self <= 0
2040+
NotNan::new(self.0.log10()).expect("Logarithm resulted in NaN")
2041+
}
2042+
fn to_degrees(self) -> Self {
2043+
NotNan(Real::to_degrees(self.0))
2044+
}
2045+
fn to_radians(self) -> Self {
2046+
NotNan(Real::to_radians(self.0))
2047+
}
2048+
fn max(self, other: Self) -> Self {
2049+
NotNan(Real::max(self.0, other.0))
2050+
}
2051+
fn min(self, other: Self) -> Self {
2052+
NotNan(Real::min(self.0, other.0))
2053+
}
2054+
fn abs_sub(self, other: Self) -> Self {
2055+
NotNan(self.0.abs_sub(other.0))
2056+
}
2057+
fn cbrt(self) -> Self {
2058+
NotNan(self.0.cbrt())
2059+
}
2060+
fn hypot(self, other: Self) -> Self {
2061+
NotNan(self.0.hypot(other.0))
2062+
}
2063+
fn sin(self) -> Self {
2064+
// Panics if self is +/-infinity
2065+
NotNan::new(self.0.sin()).expect("Sine resulted in NaN")
2066+
}
2067+
fn cos(self) -> Self {
2068+
// Panics if self is +/-infinity
2069+
NotNan::new(self.0.cos()).expect("Cosine resulted in NaN")
2070+
}
2071+
fn tan(self) -> Self {
2072+
// Panics if self is +/-infinity or self == pi/2 + k*pi
2073+
NotNan::new(self.0.tan()).expect("Tangent resulted in NaN")
2074+
}
2075+
fn asin(self) -> Self {
2076+
// Panics if self < -1.0 or self > 1.0
2077+
NotNan::new(self.0.asin()).expect("Arcsine resulted in NaN")
2078+
}
2079+
fn acos(self) -> Self {
2080+
// Panics if self < -1.0 or self > 1.0
2081+
NotNan::new(self.0.acos()).expect("Arccosine resulted in NaN")
2082+
}
2083+
fn atan(self) -> Self {
2084+
NotNan(self.0.atan())
2085+
}
2086+
fn atan2(self, other: Self) -> Self {
2087+
NotNan(self.0.atan2(other.0))
2088+
}
2089+
fn sin_cos(self) -> (Self, Self) {
2090+
// Panics if self is +/-infinity
2091+
let (a, b) = self.0.sin_cos();
2092+
(
2093+
NotNan::new(a).expect("Sine resulted in NaN"),
2094+
NotNan::new(b).expect("Cosine resulted in NaN"),
2095+
)
2096+
}
2097+
fn exp_m1(self) -> Self {
2098+
NotNan(self.0.exp_m1())
2099+
}
2100+
fn ln_1p(self) -> Self {
2101+
// Panics if self <= -1.0
2102+
NotNan::new(self.0.ln_1p()).expect("Natural logarithm resulted in NaN")
2103+
}
2104+
fn sinh(self) -> Self {
2105+
NotNan(self.0.sinh())
2106+
}
2107+
fn cosh(self) -> Self {
2108+
NotNan(self.0.cosh())
2109+
}
2110+
fn tanh(self) -> Self {
2111+
NotNan(self.0.tanh())
2112+
}
2113+
fn asinh(self) -> Self {
2114+
NotNan(self.0.asinh())
2115+
}
2116+
fn acosh(self) -> Self {
2117+
// Panics if self < 1.0
2118+
NotNan::new(self.0.acosh()).expect("Arccosh resulted in NaN")
2119+
}
2120+
fn atanh(self) -> Self {
2121+
// Panics if self < -1.0 or self > 1.0
2122+
NotNan::new(self.0.atanh()).expect("Arctanh resulted in NaN")
2123+
}
2124+
}
2125+
19602126
macro_rules! impl_float_const_method {
19612127
($wrapper:expr, $method:ident) => {
19622128
#[allow(non_snake_case)]
@@ -2333,7 +2499,7 @@ mod impl_speedy {
23332499
fn read_from<R: Reader<'a, C>>(reader: &mut R) -> Result<Self, C::Error> {
23342500
let value: T = reader.read_value()?;
23352501
Self::new(value).map_err(|error| {
2336-
speedy::Error::custom(std::format!("failed to read NotNan: {}", error)).into()
2502+
speedy::Error::custom(std::format!("failed to read NotNan: {error}")).into()
23372503
})
23382504
}
23392505

0 commit comments

Comments
 (0)