Floating-Point Arithmetic

Float and double types cause floating-point arithmetic, as specified in the IEEE 754 standard. What’s so special about this? Well, recall the inherent imprecision that exists in floating-point arithmetic. For most applications, that’s fine, but scientific or monetary computation might be better off with different numeric types (such as decimal).

But there’s more: Floating-point numbers have a series of special values to deal with infinities and mathematical nonsense also known as NaN (not a number). The C# specification contains tables to indicate the behavior of all arithmetic operators for all possible combinations of input. If the result of a computation is too large to be represented as a floating-point number, the ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.