Thanjai:
what is the purpose of fields in Float & Double
such as NaN, POSITIVE_INFINITY, NEGATIVE_INFINITY & TYPE
and how this values are obtained For an explanation of the TYPE field, take a look at
your other thread on the subject.
Gianfranco:
If YOU don't understand why they exist, then you might have
answered your own question (in some form). You are not intendend to use
them. We programmers are intended to use them. That's why we have access to them.
One of the key subjects to understand here is how floating point numbers are represented by a finite 32-bit or 64-bit binary number. For a good introduction to that topic, I recommend reading
the "Sum lack of precision!" thread over in the Cattle Drive forum. Follow the links in that conversation to further good explanations of the topic.
In a nutshell, Double.NaN represents a special bit
pattern used to create a floating-point type value that is not a number. Such a value might be the result of trying to calculate the square root of -1.
POSITIVE_INFINITY and NEGATIVE_INFINITY are often used to represent floating-point values that are either too large or too small to be represented properly in a finite binary format. These values are also used to represent the result of dividing 1.0 by 0.0 and -1.0 by 0.0 respectively.