- /* sdflognw.cpp by K.Tsuru */
- // function ID = 3406 since ver. 2.18
- /***********************************************************************
- SDouble class with binary splitting.
- It provides log(x) using Newton's method i.e. by solving the equation
- f(y) = x - exp(y) = 0 (y = log(x)).
- It does iteration
- y1 = y0 + delta
- where delta = x * exp(-y0) - 1.0
-
- Since ver.2.30 the fixed point mode is used. See RecSqrt(x).
- ***********************************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- static const char* const func = "LogNW";
- //static const SDouble ONE(1.0);
-
- SDouble LogNW(const SDouble& x) {
- // pretreatment
- SDouble X, add;
- // x = X*10^exp. log(x) = log(X)+exp*log(10), add = exp*log(10), 0< X < 1
- if( GetLogxCalcMethod(x, X, add) ) return X; // x= 1 or 10, X=0 or log(10)
-
- RealSize C;
- uint max_sz = X.MaxSize();
-
- int itrmax = howpow2( (DFIGURES*max_sz)/DOUBLE_FIG+1 ) + 6;
- int count = 0;
- uint ef = (DOUBLE_FIG*2u)/DFIGURES, fig = C.EffFigures();
- bool fullPrec = false; //calclation is done in full precision or not
-
- double xD = doubleD(X);
- SDouble y(log(xD)), delta;
-
- if(ef > fig) ef = fig;
-
- do {
- if((ef = C.SetEffFig(ef)) >= fig) fullPrec = true;
- delta = X * Exp(-y) - ONE; // considerably slower than above
- y += delta;
- ef *= 2;
- if(ef >= fig) ef = fig;
- C.SetEffFig(0);
- count++;
- } while( ( !delta.IsMLT(X) && (count < itrmax) ) || !fullPrec); // add "()" since version 2.192
- if(count >= itrmax) X.SetError(X.FATAL, func, 34010);
- y.iterationCount = count;
- y += add;
- return y;
- }
sdflognw.cpp : last modifiled at 2016/08/25 16:34:35(1,604 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).