# Fortran implementation of exponential integral

**URL:** <https://fortran-lang.discourse.group/t/fortran-implementation-of-exponential-integral/4146>\
**Category:** Help\
**Created:** [August 10, 2022, 4:51am UTC](https://fortran-lang.discourse.group/t/fortran-implementation-of-exponential-integral/4146 "2022-08-10T04:51:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicholaswogan](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@nicholaswogan](https://fortran-lang.discourse.group/u/nicholaswogan)\
**Post date:** [August 10, 2022, 4:51am UTC](https://fortran-lang.discourse.group/t/fortran-implementation-of-exponential-integral/4146/1 "2022-08-10T04:51:47Z")

</div>

Looking for a Fortran version of [scipy.special.expi — SciPy v1.9.0 Manual](https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.expi.html)

Thanks!

---

<div class="post-metadata">

**Author:** ![rgaelzer](https://avatars.discourse-cdn.com/v4/letter/r/8491ac/32.png) [@rgaelzer](https://fortran-lang.discourse.group/u/rgaelzer)\
**Post date:** [August 10, 2022, 1:27pm UTC](https://fortran-lang.discourse.group/t/fortran-implementation-of-exponential-integral/4146/3 "2022-08-10T13:27:41Z")

</div>

Have you tried the code in TOMS 683:  
[https://jblevins.org/mirror/amiller/toms683.f90](https://jblevins.org/mirror/amiller/toms683.f90)  
It’s a double complex implementation.

You can find more in the Miller library:  
[https://jblevins.org/mirror/amiller/](https://jblevins.org/mirror/amiller/)  
It has served me well over the years.

---

<div class="post-metadata">

**Author:** ![nicholaswogan](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@nicholaswogan](https://fortran-lang.discourse.group/u/nicholaswogan)\
**Post date:** [August 10, 2022, 8:02pm UTC](https://fortran-lang.discourse.group/t/fortran-implementation-of-exponential-integral/4146/4 "2022-08-10T20:02:05Z")

</div>

Thanks for the suggestions! I found what I needed in the Miller library

---

<div class="post-metadata">

**Author:** ![septc](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/septc/32/77_2.png) [@septc](https://fortran-lang.discourse.group/u/septc)\
**Post date:** [August 10, 2022, 9:45pm UTC](https://fortran-lang.discourse.group/t/fortran-implementation-of-exponential-integral/4146/5 "2022-08-10T21:45:51Z")

</div>

Though already solved, some comparison of Ei(x) for `x = 1.0`… (just for fun 🔎)

- Fortran  
[TOMS715 - Special Functions](https://people.math.sc.edu/Burkardt/f_src/toms715/toms715.html)

```fortran
  $ gfortran-10 toms715.f90 test.f90 && ./a.out
  
  program main
    implicit none
    double precision, external :: EI
    print "(f25.17)", EI( 1.0d0 ) !! 1.89511781635593657
  end

```

- C++

```cpp
  $ g++ -std=c++17 test.cpp

  #include <iostream>
  #include <cmath>
  int main() {
    printf( "%25.17f\n", std::expint( 1.0 ) ); 
    // 1.89511781635593701
  }

```

- Python

```python
  > import scipy.special
  > scipy.special.expi( 1.0 ) # 1.8951178163559368

```

- Julia

```nohighlight
  > using SpecialFunctions
  > expinti( 1.0 ) # 1.8951178163559366

```

---

<div class="post-metadata">

**Author:** ![rgaelzer](https://avatars.discourse-cdn.com/v4/letter/r/8491ac/32.png) [@rgaelzer](https://fortran-lang.discourse.group/u/rgaelzer)\
**Post date:** [August 11, 2022, 1:20pm UTC](https://fortran-lang.discourse.group/t/fortran-implementation-of-exponential-integral/4146/6 "2022-08-11T13:20:52Z")

</div>

Oh, yeah. There’s always going to occur some round-off error.  
You can verify the accuracy of the code using, e.g., MPMath ([https://mpmath.org](https://mpmath.org)):  
~\>python  
Python 3.10.6 (main, Aug 2 2022, 00:00:00) [GCC 12.1.1 20220507 (Red Hat 12.1.1-1)] on linux  
Type “help”, “copyright”, “credits” or “license” for more information.

> > > from mpmath import \*  
> > > nprint(ei(1), n= 30)  
> > > 1.89511781635593679062878891273

MPMath is a great tool to verify accuracy. An even better tool is the Arb library ([https://arblib.org](https://arblib.org)), which, besides giving arbitrary-precision solutions, also provides a maximum value for the error.
