How can I get NAN value by the function argument type?

fn get_nan<T>(x: T) -> T {
    T::NAN
}

This does not works, how can I do it?

There's no built-in way. You can use num_traits::Float::nan(), if you really need to be generic, or just fix the type as either f32 or f64.

4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.