1. /* sdfexps.cpp by K.Tsuru */
  2. // function ID 3306 DRADIX
  3. /*************************************************************************
  4. SDouble class
  5. It provides exp(x) by the series.
  6. If first != 0 calculate exp(x), else exp(x) - 1 for small x.
  7. default first = 1.
  8. **************************************************************************/
  9. #ifndef SN_H
  10. #include "sn.h"
  11. #endif
  12. static const char* func = "ExpSeries";
  13. SDouble ExpSeries(const SDouble& x, int first){
  14. #if 0 //It does not check the range of 'x' and entrusts user.
  15. int e = x.NetRdxExp();
  16. if( e > 0){ // x > 1
  17. x.SetError(x.OUT_OF_RANGE, func, 3306);
  18. } else
  19. #endif
  20. SDouble sum, delta(x);
  21. ulong k = 2uL, mt = x.SlOpMaxValue();
  22. if(first) sum = 1.0 + x;
  23. else sum = x;
  24. sum.FixedPoint(sum.RdxExp());
  25. while(delta.Sign()){
  26. delta = DsDiv(delta*x, k); //about six times faster than "delta = delta*(xn/k);".
  27. sum += delta;
  28. if( (k++) >= mt ){
  29. sum.SetError(sum.NOT_CONVERGE, func, -3306);
  30. break;
  31. }
  32. }
  33. sum.PointFree();
  34. sum.Reform(3306);
  35. sum.upToTerm = k;
  36. return sum;
  37. }

sdfexps.cpp : last modifiled at 2016/01/19 16:07:28(1,089 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).