Details about the mathematics class C #, Math, floating point number (bottom)

Source: Internet
Author: User

The float and double Floating Point data types are defined to be consistent with ANSI/IEEE Std 754-1985 (an IEEE Standard for binary floating point Arithmetic.
The float and double Floating Point data types are defined to be consistent with ANSI/IEEE Std 754-1985 (an IEEE Standard for binary floating point Arithmetic.
A float value consists of a 24-Bit Signed ending number and an 8-Bit Signed index. The precision is greater than 7 digits after the decimal point. The value range is from-3.402823*1038 to 3.402823*1038. The minimum float value greater than 0 is 1.401298*10-45. The three values correspond to float respectively. minValue, float. maxValue, float. epsilon.
The double value consists of a 53-Bit Signed ending number and an 11-Bit Signed index. The precision is about 15 to 16 digits after the decimal point. The value ranges from-1.79769313486232*10308 to 1.79769313486232*10308. The minimum double value greater than 0 is: 4.94065645841247*10-324, respectively:
Double. MinValue, double. MaxValue, double. Epsilon.
The following code divides a floating point number by 0;
Float f1 = 1;
Float f2 = 0;
Float f3 = f1/f2;
If you see the above Code, will you immediately think of DividedByZeroException. If these numbers are integers, an exception is thrown, but these numbers are floating-point numbers, and no exception is thrown here,
In fact, floating-point calculation never produces exceptions, because f2 is not really 0, it is just a number very close to 0 (For details, refer to my previous article ). In this case, f3 is equal to a special value. It is Infinity (positive Infinity ),
If you change f1 to-1, the f3 symbol is negative, and it is-Infinity (negative Infinity ).
You can even perform arithmetic operations on Infinity. For example, expression 1/f3 is equal to 0.
If f1 is changed to 0, f3 is equal to NaN (Not a Number, unknown ).
Determine whether a number is Infinity or NaN uses a Single static method:
Bool IsInfinity (float fValue); // determines whether it is infinite.
Bool IsPositiveInfinity (float fValue); // determines whether it is positive or not.
Bool IsNegativeInfinty (float fValue); // determines whether it is negative infinity.
Bool IsNaN (float fValue); // judge whether it is NaN
The Single structure also defines some constant fields.
Single. PositiveInfinity.
Single. NegativeInfinity.
Single. NaN.

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.