extracted NaN and Infinity to contstants / refactored

Using Float::NAN and Float::INFINITY if possible, but still compatible with ruby < 1.9.2 (using rescue)