// The following functions are a replacement for expm1 and log1p, which are // in C99, but not provided by MSVC 9.0 Express compiler. // returns more accurate e^x-1 for x near 0 than calculating directly double lcl_expm1(double fX) { return tanh(fX/2)*(exp(fX)+1); } //another version double lcl2_expm1(double x) { double u = exp(x); if (u == 1.0) return x; if (u-1. == -1.0) return -1.0; return (u-1.0)*x/log(u); } // returns more accurate log(1+x) for x near 0 than calculating directly double lcl_log1p(double fX) { double fU = 1.0+fX; if (fU == 1.0) return fX; else return log(fU)*fX/(fU-1); } ======= Correct values for exp(x)-1 and for log(1+x) for testing, whether the ersatz will work for you. x exp(x)-1 with MuPad ln(1+x) with MuPad -1,00000000000000E-001 -9.51625819640404E-002 -1.05360515657826E-001 -2,00000000000000E-005 -1.99998000013333E-005 -2.00002000026667E-005 -2,98700000000000E-007 -2.98699955389159E-007 -2.98700044610854E-007 -3,00000000000000E-010 -2.99999999955000E-010 -3.00000000045000E-010 -3,20000000000000E-012 -3.19999999999488E-012 -3.20000000000512E-012 -3,50000000000000E-015 -3.49999999999999E-015 -3.50000000000001E-015 -4,00000000000000E-020 -4.00000000000000E-020 -4.00000000000000E-020 -5,00000000000000E-050 -5.00000000000000E-050 -5.00000000000000E-050 -8,00000000000000E-300 -8.00000000000000E-300 0.00000000000000E+000 0,00000000000000E+000 0.00000000000000E+000 0.00000000000000E+000 8,00000000000000E-300 8.00000000000000E-300 0.00000000000000E+000 5,00000000000000E-050 5.00000000000000E-050 5.00000000000000E-050 4,00000000000000E-020 4.00000000000000E-020 4.00000000000000E-020 3,50000000000000E-015 3.50000000000001E-015 3.49999999999999E-015 3,20000000000000E-012 3.20000000000512E-012 3.19999999999488E-012 3,00000000000000E-010 3.00000000045000E-010 2.99999999955000E-010 2,98700000000000E-007 2.98700044610849E-007 2.98699955389164E-007 2,00000000000000E-005 2.00002000013333E-005 1.99998000026666E-005 1,00000000000000E-001 1.05170918075648E-001 9.53101798043249E-002 -5,00000000000000E+000 -9.93262053000915E-001 not in domain -2,00000000000000E+000 -8.64664716763387E-001 not in domain -1,00000000000000E+000 -6.32120558828558E-001 not in domain 1,00000000000000E+000 1.71828182845905E+000 6.93147180559945E-001 2,00000000000000E+000 6.38905609893065E+000 1.09861228866811E+000 5,00000000000000E+000 1.47413159102577E+002 1.79175946922805E+000