Fix ln(x) via taylor series for special case x = 1

This commit is contained in:
joba-1 2020-08-05 23:42:34 +02:00 committed by GitHub
parent d321b6cf68
commit d6bcab2920
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 0 deletions

View File

@ -116,6 +116,7 @@ double TaylorLog(double x)
// https://stackoverflow.com/questions/46879166/finding-the-natural-logarithm-of-a-number-using-taylor-series-in-c
if (x <= 0.0) { return NAN; }
if (x == 1.0) { return 0; }
double z = (x + 1) / (x - 1); // We start from power -1, to make sure we get the right power in each iteration;
double step = ((x - 1) * (x - 1)) / ((x + 1) * (x + 1)); // Store step to not have to calculate it each time
double totalValue = 0;