Add a small section for inf or nan.
2 unresolved threads
2 unresolved threads
Compare changes
```
```
```
```
The historical enumerations `enum` of C++ allow to define constants that are treated as integers, and that can be initialized from integers. By default the first value is 0 and the `enum` is incremented for each value, but it is possible to bypass these default values and provide the desired numerical value yourself.
```
```
```
```
```
```
```
```
```
The _0 notation column_ is the way to notice explicitly the type in an expression; of course any value might be used instead of 0. A `u` might be used to signal the unsigned status for integer types; for instance `3ul` means 3 as an _unsigned long_. `auto` notation below will illustrate a case in which such a notation is useful.
The STL features rather heavily a type named `std::size_t`, which by design is able to store the maximum size of a theoretically possible object of any type (including array). On most (all?) systems `std::size_t` is an alias to an `unsigned long`. More may be found about this type on [CppReference](https://en.cppreference.com/w/cpp/types/size_t). The equivalent counterpart for *signed* integers is the [`std::ptrdiff_t`](https://en.cppreference.com/w/cpp/types/ptrdiff_t), which is the signed integer type of the result of subtracting two pointers.
```
```
```
Other languages such as Python (but not its numeric modules such as _numpy_ which are using C or C++ under the hood) gets a underlying integer model that is resilient to this kind of issue but there is a performance cost behind it; types such as those used in C++ are tailored to favor optimization on your hardware.
```
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
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
```
On such trivial examples it might not seem much, but in practice it might prove incredibly useful. Consider for instance the following versions of the code for iterating over a vector with an 'historical' `for` loop (the details don't matter: we'll deal with `std::vector` in a [later notebook](../5-UsefulConceptsAndSTL/3-Containers.ipynb)):
```
```
```
```
```
```
```
```
```
I would mitigate this sentence, maybe
... All types stored especially don't go from minus infinity to infinity
Maybe an example like: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...)