How does C ++ express infinity ?, Indicates
In C ++, there may be endless situations. How to express infinity?
First, each data type of C ++ has a fixed number of digits, so that the maximum data can be expressed by the full number of digits 1. C ++ itself also defines some such constants for use. For example, if the maximum unsigned integer data is UCHAR_MAX, the decimal number is 255, the hexadecimal number is 0xff, and the maximum double data is DBL_MAX, you can call the data without including the header file, which can be found in MSDN. However, the maximum data is only the largest, but not infinite.
In VS, to represent infinity, a constant can be divided by 0. Note that this constant must be of the double type. The Compiler reports an error if the int type data is not 0. If a positive and non-zero double type data/0 is used, the resulting data is 1. # INF. This data is of all positive and infinite nature and is larger than DBL_MAX. Similarly, use a negative non-zero double data type/0 to obtain a data such as-1. # INF. This data also has all the properties of negative infinity. Note that the double type data cannot be directly set to/0,
Double s = 1.0/0;
This statement is incorrect and the compiler reports an error.
Write the following statement:
Double a = 1;
Double s = a/0;
Or
Double B = 0;
Double s = 1/B;
Or
Double a = 1;
Double B = 0;
Double s = a/B;
Yes, you can find s = 1. # INF.
Note: the denominator of a numerator cannot be set to 0 at the same time. Otherwise, the result is 1. # IND. This data is neither positive infinity nor negative infinity, nor zero.