Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

NaN - Not a Number

  • NaN

  • sqrt

  • Floating point numbers, f32 or f64, can also represent a value called NaN or Not a Number.

  • One way to get the number is to take the square root of -1.0.

  • Most operations with a NaN result in NaN.

  • Two NaN values are not equal.

  • The sqrt (square root) method is not implemented for integers.

fn main() {
    let number: f32 = -1.0;
    let i = number.sqrt();
    println!("{}", i);
    let j = number.sqrt();

    println!("{}", i + 10.0);
    println!("{}", i == j);
}
NaN
NaN
false