Infinity in C # has a little pit.

Source: Internet
Author: User

(This article also published in my public number "dotnet daily Essence article", Welcome to the right QR code to pay attention to. )

Yesterday at home something, the Internet is not convenient, there is no push article. Today is very tired, also not lengthy. A brief introduction to a small hole recently encountered.

We know that there are several numeric types in C #: int, long, decimal, float, and double. For the first three kinds, if except 0, you will be prompted for an expression error (write a number directly) or a DivideByZeroException exception (using a variable), for the next two, except 0 will be positive and negative infinity, unless you are 0.0/0.0 then get Nan (not a number). This is what most of the references tell you. such as "read the original" This easy-to-understand article.

Recently, the previous code has a bug, always appear infinity, and then troubleshoot all division expressions, the problem will not be resolved. After tracing the value of the variable before the infinity, and discovering the multiplication of "1E+300 * 1E+10", the code logic is carefully studied, and some variables (double types) are repeatedly multiplied and become infinitely large. Realize that not only will there be infinity in addition to 0, but the multiplication of large numbers will also occur infinitely large. Everyone be careful later.

Original address:

Infinity in C # has a little pit.

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: 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.