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.