You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: GlobalCode/AltNum/AltNumDebug.hpp
+37-42Lines changed: 37 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -276,52 +276,47 @@ namespace BlazesRusDebug
276
276
//if (value <= 0) {}else//Error if equal or less than 0
277
277
if (value==MediumDec::One)
278
278
return MediumDec::Zero;
279
-
//if (value.IntValue==0)//Threshold between 0 and 2 based on Taylor code series from https://stackoverflow.com/questions/26820871/c-program-which-calculates-ln-for-a-given-variable-x-without-using-any-ready-f
280
-
//{
281
-
// double fthreshold = 0.000000005;
282
-
// double fbase = fvalue - 1; // Base of the numerator; exponent will be explicit
283
-
// int den = 2; // Denominator of the nth term
284
-
// bool posSign = true; // Used to swap the sign of each term
} while (AddRes > MediumDec::JustAboveZero);//Total Result should be -0.346573590279972654708616060729088284037750067180127627060340004746696810984847357802931663498209344
317
+
return TotalRes * 2;//Should result in -0.693147180559
318
+
}
319
+
elseif(value.IntValue==1)
325
320
{
326
321
MediumDec threshold = MediumDec::FiveMillionth;
327
322
MediumDec base = value - 1; // Base of the numerator; exponent will be explicit
Copy file name to clipboardExpand all lines: GlobalCode/AltNum/FloatingOperations.hpp
+70Lines changed: 70 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -248,6 +248,76 @@ namespace BlazesFloatingCode
248
248
}
249
249
}
250
250
251
+
/// <summary>
252
+
/// Natural log (Equivalent to Log_E(value))
253
+
/// </summary>
254
+
/// <param name="value">The target value.</param>
255
+
/// <returns>double</returns>
256
+
staticdoubleLnRefV2(double& value)
257
+
{
258
+
//if (value <= 0) {}else//Error if equal or less than 0
259
+
if (value == 1.0)
260
+
return0.0;
261
+
if(value<1.0)
262
+
{
263
+
double W = (value - 1.0) / (value + 1.0);//(-0.5)/(1.5)=-1/3
264
+
double TotalRes = W;
265
+
W *= -1;
266
+
double LastPow = W;
267
+
double WSquared = W * W;
268
+
double AddRes;
269
+
int WPow = 3;
270
+
do
271
+
{
272
+
LastPow *= WSquared;
273
+
AddRes = LastPow / WPow;
274
+
TotalRes -= AddRes;
275
+
WPow += 2;
276
+
} while (AddRes > 0.000000001);//Total Result should be -0.346573590279972654708616060729088284037750067180127627060340004746696810984847357802931663498209344
277
+
return TotalRes * 2;//Should result in -0.693147180559
278
+
}
279
+
elseif (value < 2.0)//Threshold between 0 and 2 based on Taylor code series from https://stackoverflow.com/questions/26820871/c-program-which-calculates-ln-for-a-given-variable-x-without-using-any-ready-f
280
+
{
281
+
double threshold = 0.000000005;
282
+
double base = value - 1; // Base of the numerator; exponent will be explicit
283
+
int den = 1; // Denominator of the nth term
284
+
bool posSign = true; // Used to swap the sign of each term
285
+
double term = base; // First term
286
+
double prev; // Previous sum
287
+
double result = term; // Kick it off
288
+
289
+
do
290
+
{
291
+
den++;
292
+
posSign = !posSign;
293
+
term *= base;
294
+
prev = result;
295
+
if (posSign)
296
+
result += term / den;
297
+
else
298
+
result -= term / den;
299
+
} while (abs(prev - result) > threshold);
300
+
301
+
return result;
302
+
}
303
+
else//Returns a positive value(http://www.netlib.org/cephes/qlibdoc.html#qlog)
304
+
{//Increasing iterations brings closer to accurate result(Larger numbers need more iterations to get accurate level of result)
0 commit comments