Skip to content

Commit 81faafe

Browse files
fp4codestevengjararslan
authored
Added faddeeva function (#88)
Co-authored-by: Steven G. Johnson <stevenj@mit.edu> Co-authored-by: Alex Arslan <ararslan@comcast.net>
1 parent 07a890c commit 81faafe

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

docs/src/functions_list.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SpecialFunctions.erfcx
1111
SpecialFunctions.logerfc
1212
SpecialFunctions.logerfcx
1313
SpecialFunctions.erfi
14+
SpecialFunctions.faddeeva
1415
SpecialFunctions.dawson
1516
SpecialFunctions.erfinv
1617
SpecialFunctions.erfcinv

docs/src/functions_overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Here the *Special Functions* are listed according to the structure of [NIST Digi
4747
| [`erfi(x)`](@ref SpecialFunctions.erfi) | imaginary error function defined as ``-i \operatorname{erf}(ix)`` |
4848
| [`erfinv(x)`](@ref SpecialFunctions.erfinv) | inverse function to [`erf()`](@ref SpecialFunctions.erf) |
4949
| [`dawson(x)`](@ref SpecialFunctions.dawson) | scaled imaginary error function, a.k.a. Dawson function, i.e. accurate ``\frac{\sqrt{\pi}}{2} e^{-x^2} \operatorname{erfi}(x)`` for large ``x`` |
50+
| [`faddeeva(x)`](@ref SpecialFunctions.faddeeva) | [Faddeeva function](https://en.wikipedia.org/wiki/Faddeeva_function), equivalent to ``\operatorname{erfcx}(-ix)`` |
5051

5152

5253
## [Airy and Related Functions](https://dlmf.nist.gov/9)

src/SpecialFunctions.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export
5656
logerf,
5757
logerfc,
5858
logerfcx,
59+
faddeeva,
5960
eta,
6061
digamma,
6162
invdigamma,

src/erf.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ for f in (:erf, :erfc)
2828
end
2929
end
3030

31-
for f in (:erfcx, :erfi, :dawson)
31+
for f in (:erfcx, :erfi, :dawson, :faddeeva)
3232
internalf = Symbol(:_, f)
33-
openspecfunfsym = Symbol(:Faddeeva_, f === :dawson ? :Dawson : f)
33+
openspecfunfsym = Symbol(:Faddeeva_, f === :dawson ? :Dawson : f === :faddeeva ? :w : f)
3434
openspecfunfF64 = QuoteNode(Symbol(openspecfunfsym, :_re))
3535
openspecfunfCF64 = QuoteNode(openspecfunfsym)
3636
@eval begin
@@ -46,6 +46,8 @@ for f in (:erfcx, :erfi, :dawson)
4646
end
4747
end
4848

49+
faddeeva(x::Real) = faddeeva(complex(x))
50+
4951
# MPFR has an open TODO item for this function
5052
# until then, we use [DLMF 7.12.1](https://dlmf.nist.gov/7.12.1) for the tail
5153
function _erfcx(x::BigFloat)
@@ -213,6 +215,16 @@ See also: [`erfi(x)`](@ref erfi).
213215
"""
214216
dawson
215217

218+
"""
219+
faddeeva(z)
220+
221+
Compute the Faddeeva function of complex `z`, defined by
222+
``e^{-z^2} \\operatorname{erfc}(-iz)``.
223+
Note that this function, also named `w` (original Faddeeva package) or `wofz` (Scilab package),
224+
is equivalent to``\\operatorname{erfcx}(-iz)``.
225+
"""
226+
faddeeva
227+
216228
@doc raw"""
217229
erfinv(x)
218230

test/erf.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
@test dawson(Float16(1)) 0.53807950691276841914 rtol=2*eps(Float16)
5656
@test dawson(Float32(1)) 0.53807950691276841914 rtol=2*eps(Float32)
5757
@test dawson(Float64(1)) 0.53807950691276841914 rtol=2*eps(Float64)
58+
59+
@test faddeeva(0) == faddeeva(0//1) == 1
60+
@test faddeeva(Float16(1)) 0.36787944117144233402+0.60715770584139372446im rtol=2*eps(Float16)
61+
@test faddeeva(Float32(1)) 0.36787944117144233402+0.60715770584139372446im rtol=2*eps(Float32)
62+
@test faddeeva(Float64(1)) 0.36787944117144233402+0.60715770584139372446im rtol=2*eps(Float64)
5863
end
5964

6065
@testset "complex arguments" begin
@@ -81,6 +86,10 @@
8186
@test dawson(ComplexF16(1+2im)) -13.388927316482919244-11.828715103889593303im
8287
@test dawson(ComplexF32(1+2im)) -13.388927316482919244-11.828715103889593303im
8388
@test dawson(ComplexF64(1+2im)) -13.388927316482919244-11.828715103889593303im
89+
90+
@test faddeeva(ComplexF16(1+2im)) 0.21849261527489066692+0.09299780939260188228im
91+
@test faddeeva(ComplexF32(1+2im)) 0.21849261527489066692+0.09299780939260188228im
92+
@test faddeeva(ComplexF64(1+2im)) 0.21849261527489066692+0.09299780939260188228im
8493
end
8594

8695
@testset "BigFloat arguments" begin
@@ -102,6 +111,8 @@
102111

103112
@test_throws MethodError dawson(BigFloat(1))
104113

114+
@test_throws MethodError faddeeva(BigFloat(1))
115+
105116
for y in (big"1e-1000", big"1e-60", big"0.1", big"0.5", big"1.0", 1+big"1e-50", big"1.2", 2-big"1e-50")
106117
@test erfc(erfcinv(y)) y
107118
end
@@ -126,6 +137,7 @@
126137
@test_throws MethodError erfinv(NotAFloat())
127138
@test_throws MethodError erfcinv(NotAFloat())
128139
@test_throws MethodError dawson(NotAFloat())
140+
@test_throws MethodError faddeeva(NotAFloat())
129141
end
130142

131143
@testset "inverse" begin

0 commit comments

Comments
 (0)