Add a small section for inf or nan.
Closes #129 (closed)
Merge request reports
Activity
requested review from @vrouvrea
assigned to @sgilles
397 "std::cout << \"Is \" << x << \" infinite ? \" << std::isinf(x) << std::endl;\n", 398 "std::cout << \"Is \" << x << \" infinite ? \" << std::isinf(x) << std::endl;\n", 399 "\n", 400 "const double nan = std::nan(\"Chars\");\n", 401 "\n", 402 "std::cout << \"Is \" << nan << \" infinite ? \" << std::isinf(nan) << std::endl;\n", 403 "std::cout << \"Is \" << nan << \" not-a-number ? \" << std::isnan(nan) << std::endl;\n", 404 "\n", 405 "std::cout << \"The unnatural property of nan is that the expression 'nan == nan' is \" << (nan == nan) << \"!\" << std::endl;\n" 406 ] 407 }, 408 { 409 "cell_type": "markdown", 410 "metadata": {}, 411 "source": [ 412 "There are subtleties about NaN (see [Cppreference](https://en.cppreference.com/w/cpp/numeric/math/nan)) but in most cases you don't need to bother much with either `inf` or `nan`, except if you have reasons to think your computation may produce either of them. In that case, you may want to check your value is correct with `std::isfinite` ([Cppreference](https://en.cppreference.com/w/cpp/numeric/math/isfinite))." Should we talk about this behaviour:
std::cout << "double [min, max] = [" << std::numeric_limits<double>::lowest() << ", " << std::numeric_limits<double>::max() << "]" << std::endl; // double [min, max] = [-1.79769e+308, 1.79769e+308] // You must substract or add something significant enough to be taken into account std::cout << "double [min-1.79769e+300, max+1.79769e+300] = [" << std::numeric_limits<double>::lowest()-1.79769e+300 << ", " << std::numeric_limits<double>::max()+1.79769e+300 << "]" << std::endl; // double [min-1.79769e+300, max+1.79769e+300] = [-inf, inf] std::cout << 0. / 0. << std::endl; // nan std::cout << 0 / 0 << std::endl; // Floating point exception(core dumped)
Which is not the same if the type does not have an infinity or nan values
276 276 "\n", 277 277 "#### Numeric limits\n", 278 278 "\n", 279 279 "Always keep in mind the types of the computer don't match the abstract concept you may use in mathematics... The types stored especially don't go from minus infinity to infinity:" I would mitigate this sentence, maybe
... All types stored especially don't go from minus infinity to infinity
Maybe an example like:std::cout << "int [min-1, max+1] = [" << std::numeric_limits<int>::lowest() - 1 << ", " << std::numeric_limits<int>::max() +1 << "]" << std::endl; // int [min-1, max+1] = [2147483647, -2147483648]
To be discussed...
Just below this sentence there is a wall a min/max, and just below the illustration of what happens if we add 1... So for me all is already there, but clearly it's not properly presented. The best is maybe that you propose an alternate way of presenting it? (I don't feel up to the task as I'm fine with current content...)
mentioned in merge request !105 (merged)