Skip to content

Commit

Permalink
Added implementation to docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikola-Mircic committed Nov 26, 2024
1 parent 7652410 commit 2fecb19
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/math/exp_logn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""

Expand Down

0 comments on commit 2fecb19

Please sign in to comment.