From 2fecb19ab05c97ffd6f9d22b459066d22e85ac0a Mon Sep 17 00:00:00 2001 From: Nikola-Mircic Date: Tue, 26 Nov 2024 23:08:35 +0100 Subject: [PATCH] Added implementation to docstring --- src/math/exp_logn.jl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/math/exp_logn.jl b/src/math/exp_logn.jl index 349fe28..d66e52e 100644 --- a/src/math/exp_logn.jl +++ b/src/math/exp_logn.jl @@ -16,6 +16,27 @@ exp_logn(2, -2) # returns 0.25 exp_logn(2, -5) # returns 0.03125 ``` +# Implementation +```julia +function exp_logn(x::Number, n::Int) + if n == 0 + return 1 + elseif n < 0 + return 1/exp_logn(x, -n) + else + tmp = exp_logn(x, div(n,2)) + + if n%2 == 0 + # If n is even, x^n = x^(n/2) * x^(n/2) + return tmp * tmp + else + # else, x^n = x^(n/2) * x^(n/2) * x + return tmp * tmp * x + end + end +end +``` + Contributed by [Nikola Mircic](https://www.github.com/Nikola-Mircic) """