You are incrementing j
each time round your loop, but not jd
. Therefore your expression:
epx += ( pow(xd,jd) / fact(i) ); //static_cast
is effectively:
epx += ( pow(xd, 1.0) / fact(i) ); //static_cast
each time.
Move this line:
double jd = static_cast<double>(j);
inside your loop or just increment jd
directly.