The 'infinity' comes from here:
CND = 1 - 1 / Sqrt(2 * 3.14159) * Power(cE,(Power(-L , 2) / 2)) * (a1 * K + a2 * Power(K , 2) + a3 * Power(K , 3) + a4 * Power(K , 4) + a5 * Power(K , 5))
must be:
CND = 1 - 1 / Sqrt(2 * 3.14159) * Power(cE,(-Power(L , 2) / 2)) * (a1 * K + a2 * Power(K , 2) + a3 * Power(K , 3) + a4 * Power(K , 4) + a5 * Power(K , 5))
The '-' sign is at the wrong place.
The NaN can come from here:
BlackScholes = S * CND*(d1) - X * Power(cE, -r * T) * CND*(v * Sqrt(T-d1))
if d1 > T then Sqrt of a negative number raises the NaN error.
Best regards.