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

Add more methods from num_traits::Float #2

Open
jannschu opened this issue May 3, 2020 · 3 comments
Open

Add more methods from num_traits::Float #2

jannschu opened this issue May 3, 2020 · 3 comments

Comments

@jannschu
Copy link

jannschu commented May 3, 2020

There are a couple of occasions where I regularly have to add an additional num_traits::Float bound.

Methods I need from num_traits::Float include the following:

  • min_positive_value
  • is_nan
  • nan
  • infinity and neg_infinity
  • max and min with the NaN semantics
  • copysign

Is the RealField suitable for these methods or is it intended to be more abstract, i.e., it not necessarily represents these floating point semantics?

@astraw
Copy link

astraw commented Nov 8, 2020

For what it is worth, here is what I am using for is_nan to avoid adding this bound:

#[inline]
fn is_nan<R: RealField>(x: R) -> bool {
    let zero = R::zero();
    if x < zero {
        false
    } else {
        if x >= zero {
            false
        } else {
            true
        }
    }
}

@lelongg
Copy link

lelongg commented Apr 14, 2021

same but more succinct

#[inline]
fn is_nan<R: RealField>(x: R) -> bool {
    x.partial_cmp(&R::zero()).is_none()
}

@astraw
Copy link

astraw commented Sep 22, 2021

Thanks @lelongg . Also clippy does not complain about your version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants