- /* sdfexps.cpp by K.Tsuru */
- // function ID 3306 DRADIX
- /*************************************************************************
- SDouble class
- It provides exp(x) by the series.
- If first != 0 calculate exp(x), else exp(x) - 1 for small x.
- default first = 1.
- **************************************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- static const char* func = "ExpSeries";
- SDouble ExpSeries(const SDouble& x, int first){
- #if 0 //It does not check the range of 'x' and entrusts user.
- int e = x.NetRdxExp();
- if( e > 0){ // x > 1
- x.SetError(x.OUT_OF_RANGE, func, 3306);
- } else
- #endif
- SDouble sum, delta(x);
- ulong k = 2uL, mt = x.SlOpMaxValue();
-
- if(first) sum = 1.0 + x;
- else sum = x;
-
- sum.FixedPoint(sum.RdxExp());
-
- while(delta.Sign()){
- delta = DsDiv(delta*x, k); //about six times faster than "delta = delta*(xn/k);".
- sum += delta;
- if( (k++) >= mt ){
- sum.SetError(sum.NOT_CONVERGE, func, -3306);
- break;
- }
- }
- sum.PointFree();
- sum.Reform(3306);
- sum.upToTerm = k;
- return sum;
- }
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).