From 79c38646875acdb2146bde63c9f16fbcc023cc8c Mon Sep 17 00:00:00 2001 From: fdai7848 Date: Wed, 31 Jan 2024 10:35:43 +0100 Subject: [PATCH] implement first revision for ln with halley-newton-approx --- src/exponent.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/exponent.c b/src/exponent.c index 2cfecf5..b37deab 100644 --- a/src/exponent.c +++ b/src/exponent.c @@ -46,4 +46,24 @@ double exponential(double x){ sum += (1.0/fac(i)*(expIN(i,x))); } return sum; +} + +double absD(double x){ + if(x<0){ + return -1 * x; + } + return x; +} + +double logN(double x, double eps){ + double yn = x - 1.0; + double yn1 = yn; + + do + { + yn = yn1; + yn1 = yn + 2 * (x - exponential(yn)) / (x + exponential(yn)); + } while (absD(yn - yn1) > eps); + + return yn1; } \ No newline at end of file