The IEEE Floating Point Arithmetic Standard (IEEE 754) is the most widely used floating point standard, followed by many hardware and software implementations, including the C # compiler.
This means that a floating point variable in C # may contain a bit pattern representing strange creatures such as PositiveInfinity, NegativeInfinity and Not-a-Number (abbreviated as NaN). According to IEEE 754 arithmetic rules, any of these non-finite floating point values ββcan be generated by certain operations. For example, an invalid floating point operation, such as dividing zero by zero, results in NaN.
In your specific examples, you can see that C # (unlike VB) overloads the / operator to mean either integer or floating point division, depending on the number types of the numbers involved.
In the first example, the compiler sees 1.0 and therefore uses floating point division and transfers the result to a floating point variable. This variable contains a representation of infinity.
In the second example, the compiler sees 1 and therefore uses integer division and puts the result in an integer variable. Since integral types in C # use two complement systems to represent and do not use any special bit patterns to represent infinity (or NaN), the compiler gives an error.
There are other interesting subtleties with floating point . And it's worth reading Eric Lippert 's blog entry on this subject.
RoadWarrior Nov 24 '10 at 0:23 2010-11-24 00:23
source share