# Is there a fast way to evaluate the exp() function in Julia?

**URL:** <https://discourse.julialang.org/t/is-there-a-fast-way-to-evaluate-the-exp-function-in-julia/76287>\
**Category:** Performance\
**Tags:** question\
**Created:** [February 12, 2022, 8:08am UTC](https://discourse.julialang.org/t/is-there-a-fast-way-to-evaluate-the-exp-function-in-julia/76287 "2022-02-12T08:08:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![maphdze](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@maphdze](https://discourse.julialang.org/u/maphdze)\
**Post date:** [February 12, 2022, 8:08am UTC](https://discourse.julialang.org/t/is-there-a-fast-way-to-evaluate-the-exp-function-in-julia/76287/1 "2022-02-12T08:08:52Z")

</div>

This post was temporarily hidden by the community for possibly being off-topic, unfocused, inappropriate, or spammy.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [February 12, 2022, 8:45am UTC](https://discourse.julialang.org/t/is-there-a-fast-way-to-evaluate-the-exp-function-in-julia/76287/2 "2022-02-12T08:45:20Z")

</div>

Isn’t this the same question you asked a few hours ago in

> [@Accelerate pairwise damage computation](https://discourse.julialang.org/t/accelerate-pairwise-damage-computation/76278):
>
> Can someone help me to accelerate the pairwise damage computation? This problem is very similar to the one in [Accelerate pairwise L-J force computation](https://discourse.julialang.org/t/accelerate-pairwise-lennard-jones-force-computation/67321/46). And I adopted the conclusion that the pairlist should be sorted first to have a better performance. The following codes are modified based on the one in [Accelerate pairwise Lennard-Jones force computation](https://discourse.julialang.org/t/accelerate-pairwise-lennard-jones-force-computation/67321/46) given by @ [lmiq](https://discourse.julialang.org/u/lmiq) using BenchmarkTools using StaticArrays const λ = 1.0E-6 @inline @fastmath function damage\_pair!(f,x,y,i,j,d) new\_d = 0.0…

Please don’t double post

---

<div class="post-metadata">

**Author:** ![maphdze](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@maphdze](https://discourse.julialang.org/u/maphdze)\
**Post date:** [February 12, 2022, 9:05am UTC](https://discourse.julialang.org/t/is-there-a-fast-way-to-evaluate-the-exp-function-in-julia/76287/3 "2022-02-12T09:05:03Z")

</div>

I am sorry. I have flagged this to the admin to delate it.

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [February 12, 2022, 9:21am UTC](https://discourse.julialang.org/t/is-there-a-fast-way-to-evaluate-the-exp-function-in-julia/76287/4 "2022-02-12T09:21:01Z")

</div>

There exists [`Base.Math.exp_fast`](https://github.com/JuliaLang/julia/blob/master/base/fastmath.jl).

Compare for example `@code_native Base.Math.exp_fast.([1., 2., 3., 4.])` with `@code_native exp.([1., 2., 3., 4.])`…

---

<div class="post-metadata">

**Author:** ![maphdze](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@maphdze](https://discourse.julialang.org/u/maphdze)\
**Post date:** [February 12, 2022, 9:40am UTC](https://discourse.julialang.org/t/is-there-a-fast-way-to-evaluate-the-exp-function-in-julia/76287/5 "2022-02-12T09:40:36Z")

</div>

Thanks for your reply. Is the Base.Math.exp\_fast the same as using `@fastmath` which I already done in the posted code?

---

<div class="post-metadata">

**Author:** ![maphdze](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@maphdze](https://discourse.julialang.org/u/maphdze)\
**Post date:** [February 12, 2022, 9:44am UTC](https://discourse.julialang.org/t/is-there-a-fast-way-to-evaluate-the-exp-function-in-julia/76287/6 "2022-02-12T09:44:49Z")

</div>

Well, I have just tried it and the performance is the same as using `@fastmath`.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [February 12, 2022, 9:47am UTC](https://discourse.julialang.org/t/is-there-a-fast-way-to-evaluate-the-exp-function-in-julia/76287/7 "2022-02-12T09:47:53Z")

</div>

> [@maphdze](#):
>
> Is the Base.Math.exp\_fast the same as using `@fastmath`

Yes

---

<div class="post-metadata">

**Author:** ![FrancisKing](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/francisking/32/24966_2.png) [@FrancisKing](https://discourse.julialang.org/u/FrancisKing)\
**Post date:** [February 12, 2022, 10:20am UTC](https://discourse.julialang.org/t/is-there-a-fast-way-to-evaluate-the-exp-function-in-julia/76287/8 "2022-02-12T10:20:24Z")

</div>

I don’t know how accurate the calculation needs to be. But you could pre-compute an array of values - then it’s just a question of a lookup. That should be quite fast.

---

<div class="post-metadata">

**Author:** ![maphdze](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@maphdze](https://discourse.julialang.org/u/maphdze)\
**Post date:** [February 12, 2022, 12:25pm UTC](https://discourse.julialang.org/t/is-there-a-fast-way-to-evaluate-the-exp-function-in-julia/76287/9 "2022-02-12T12:25:41Z")

</div>

Thanks for your suggestion! Do you mean interplation? Actually the x in exp(x) is not known beforehand, and if we pre-cmpute an array we have to look up in the array and then do some interplation. I guess the looking up process maybe time-consuming.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [February 12, 2022, 2:32pm UTC](https://discourse.julialang.org/t/is-there-a-fast-way-to-evaluate-the-exp-function-in-julia/76287/10 "2022-02-12T14:32:28Z")

</div>



---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [February 12, 2022, 2:32pm UTC](https://discourse.julialang.org/t/is-there-a-fast-way-to-evaluate-the-exp-function-in-julia/76287/11 "2022-02-12T14:32:34Z")

</div>


