How does C ++ express infinity ?, Indicates

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.