|
25 | 25 |
|
26 | 26 | ## convert irrationals to float
|
27 | 27 |
|
28 |
| -@test isapprox(@inferred(lambertw(pi)), 1.0736581947961492) |
29 |
| -@test isapprox(@inferred(lambertw(pi, 0)), 1.0736581947961492) |
| 28 | +@test @inferred(lambertw(pi)) ≈ 1.0736581947961492 |
| 29 | +@test @inferred(lambertw(pi, 0)) ≈ 1.0736581947961492 |
30 | 30 |
|
31 | 31 | ### infinite args or return values
|
32 | 32 |
|
|
53 | 53 | for (z, k, res) in [(0, 0 , 0), (complex(0, 0), 0 , 0),
|
54 | 54 | (complex(0.0, 0), 0 , 0), (complex(1.0, 0), 0, 0.567143290409783873)]
|
55 | 55 | if Int != Int32
|
56 |
| - @test isapprox(lambertw(z, k), res) |
57 |
| - @test isapprox(lambertw(z), res) |
| 56 | + @test lambertw(z, k) ≈ res |
| 57 | + @test lambertw(z) ≈ res |
58 | 58 | else
|
59 |
| - @test isapprox(lambertw(z, k), res; rtol = 1e-14) |
60 |
| - @test isapprox(lambertw(z), res; rtol = 1e-14) |
| 59 | + @test lambertw(z, k) ≈ res rtol=1e-14 |
| 60 | + @test lambertw(z) ≈ res rtol=1e-14 |
61 | 61 | end
|
62 | 62 | end
|
63 | 63 |
|
64 |
| -for (z, k) in ((complex(1, 1), 2), (complex(1, 1), 0), (complex(.6, .6), 0), |
65 |
| - (complex(.6, -.6), 0)) |
66 |
| - let w |
67 |
| - @test (w = lambertw(z, k) ; true) |
68 |
| - @test abs(w*exp(w) - z) < 1e-15 |
69 |
| - end |
| 64 | +@testset "complex z=$z, k=$k" for (z, k) in |
| 65 | + ((complex(1, 1), 2), (complex(1, 1), 0), (complex(.6, .6), 0), |
| 66 | + (complex(.6, -.6), 0)) |
| 67 | + w = lambertw(z, k) |
| 68 | + @test w*exp(w) ≈ z atol=1e-15 |
70 | 69 | end
|
71 | 70 |
|
72 |
| -@test abs(lambertw(complex(-3.0, -4.0), 0) - Complex(1.075073066569255, -1.3251023817343588)) < 1e-14 |
73 |
| -@test abs(lambertw(complex(-3.0, -4.0), 1) - Complex(0.5887666813694675, 2.7118802109452247)) < 1e-14 |
74 |
| -@test (lambertw(complex(.3, .3), 0); true) |
| 71 | +@test lambertw(complex(-3.0, -4.0), 0) ≈ Complex(1.075073066569255, -1.3251023817343588) atol=1e-14 |
| 72 | +@test lambertw(complex(-3.0, -4.0), 1) ≈ Complex(0.5887666813694675, 2.7118802109452247) atol=1e-14 |
| 73 | +@test lambertw(complex(.3, .3)) ≈ Complex(0.26763519642648767, 0.1837481231767825) |
75 | 74 |
|
76 | 75 | # bug fix
|
77 | 76 | # The routine will start at -1/e + eps * im, rather than -1/e + 0im,
|
78 | 77 | # otherwise root finding will fail
|
79 |
| -if Int != Int32 |
80 |
| - @test abs(lambertw(-inv(MathConstants.e) + 0im, -1)) == 1 |
81 |
| -else |
82 |
| - @test abs(lambertw(-inv(MathConstants.e) + 0im, -1) + 1) < 1e-7 |
83 |
| -end |
| 78 | +@test lambertw(-inv(MathConstants.e) + 0im, -1) ≈ -1 atol=1e-7 |
| 79 | + |
84 | 80 | # lambertw for BigFloat is more precise than Float64. Note
|
85 | 81 | # that 70 digits in test is about 35 digits in W
|
86 |
| -let W |
87 |
| - for z in [BigFloat(1), BigFloat(2), complex(BigFloat(1), BigFloat(1))] |
88 |
| - @test (W = lambertw(z); true) |
89 |
| - @test abs(z - W * exp(W)) < BigFloat(1)^(-70) |
90 |
| - end |
| 82 | +@testset "lambertw() for BigFloat z=$z" for z in |
| 83 | + [BigFloat(1), BigFloat(2), complex(BigFloat(1), BigFloat(1))] |
| 84 | + W = lambertw(z) |
| 85 | + @test z ≈ W*exp(W) atol=BigFloat(10)^(-70) |
91 | 86 | end
|
92 | 87 |
|
93 | 88 | ### ω constant
|
@@ -117,36 +112,24 @@ end
|
117 | 112 |
|
118 | 113 | if Int != Int32
|
119 | 114 |
|
120 |
| -# Test double-precision expansion near branch point using BigFloats |
121 |
| -let sp = precision(BigFloat), z = BigFloat(1)/10^12, wo, xdiff |
122 |
| - setprecision(2048) |
123 |
| - for i in 1:300 |
124 |
| - innerarg = z - inv(big(MathConstants.e)) |
| 115 | +@testset "double-precision expansion near branch point using BigFloats" begin |
| 116 | + setprecision(2048) do |
| 117 | + z = BigFloat(10)^(-12) |
| 118 | + for _ in 1:300 |
| 119 | + innerarg = z - inv(big(MathConstants.e)) |
125 | 120 |
|
126 |
| - # branch k = 0 |
127 |
| - @test (wo = lambertwbp(Float64(z)); xdiff = abs(-1 + wo - lambertw(innerarg)); true) |
128 |
| - if xdiff > 5e-16 |
129 |
| - println(Float64(z), " ", Float64(xdiff)) |
130 |
| - end |
131 |
| - @test xdiff < 5e-16 |
| 121 | + @test lambertwbp(Float64(z)) ≈ 1 + lambertw(innerarg) atol=5e-16 |
| 122 | + @test lambertwbp(Float64(z), -1) ≈ 1 + lambertw(innerarg, -1) atol=5e-16 |
| 123 | + z *= 1.1 |
| 124 | + if z > 0.23 break end |
132 | 125 |
|
133 |
| - # branch k = -1 |
134 |
| - @test (wo = lambertwbp(Float64(z), -1); xdiff = abs(-1 + wo - lambertw(innerarg, -1)); true) |
135 |
| - if xdiff > 5e-16 |
136 |
| - println(Float64(z), " ", Float64(xdiff)) |
137 | 126 | end
|
138 |
| - @test xdiff < 5e-16 |
139 |
| - z *= 1.1 |
140 |
| - if z > 0.23 break end |
141 |
| - |
142 | 127 | end
|
143 |
| - setprecision(sp) |
144 | 128 | end
|
145 | 129 |
|
146 | 130 | # test the expansion about branch point for k=-1,
|
147 | 131 | # by comparing to exact BigFloat calculation.
|
148 |
| -@test @inferred(lambertwbp(1e-20, -1)) - 1 - lambertw(-inv(big(MathConstants.e)) + BigFloat(10)^BigFloat(-20), -1) < 1e-16 |
149 |
| - |
150 |
| -@test abs(@inferred(lambertwbp(Complex(.01, .01), -1)) - Complex(-0.2755038208041206, -0.1277888928494641)) < 1e-14 |
| 132 | +@test @inferred(lambertwbp(1e-20, -1)) ≈ 1 + lambertw(-inv(big(MathConstants.e)) + BigFloat(10)^(-20), -1) atol=1e-16 |
| 133 | +@test @inferred(lambertwbp(Complex(.01, .01), -1)) ≈ Complex(-0.2755038208041206, -0.1277888928494641) atol=1e-14 |
151 | 134 |
|
152 | 135 | end # if Int != Int32
|
0 commit comments