First of all we have to learn how the number is represented as the float point and double in the memory.
The general number is of the form: 1.M * 2^e.
(where the M is called mantissa and the e is the exponent in the excess-127)
In floating point
The MSB(Most significant bit) is used as sign bit and the bit number from 23 to 31 is used for the exponential value in the form of excess-127 and the bit number from 0 to 30 is used for storing the mantissa.
In Double
The MSB(Most significant bit) is used as sign bit and the bit number from 52 to 63 is used for the exponential value in the form of excess-127 and the bit number from 0 to is used for storing the mantissa.
so now we are in position to understand the NaN, Infinity representation in the float or double.
NaN(Not an Number)
In the representation of the NaN all the Exponent bits are 1 and the Mantissa bits can be anything and it does not matter that it is in float or decimal.
Infinity
In the representation of the Infinity all the Exponent bits are 1 and the Mantissa bits are 0 and it does not matter that it is in float or decimal.
The positive Infinity is represent just by same as above but the sign bit is 0 and the negative infinity is represented also just by same but the sign bit is here 1.