Special Floating Point Quantities#
IEEE 754 defines a few special quantities:
NaN(not a number) is the result of0.0/0.0orstd::sqrt(-1.0)Inf(infinity) is the result of1.0/0.0-0is a valid number and the standard says that-0is equivalent to0
We can test on these values using std::isnan and std::isinf. For instance, here we generate a NaN:
#include <iostream>
#include <cmath>
int main() {
double x{-1.0};
double y = std::sqrt(x);
std::cout << y << std::endl;
std::cout << std::isnan(y) << std::endl;
}