Skip to content

Commit

Permalink
Fix JuliaLang#11512 (disable computation for Complex BigInt/BigFloat …
Browse files Browse the repository at this point in the history
…type)

We implement an explicit type checking and disable Complex{BigInt} and Complex{BigFloat}.
Currently only do for Bessel and Airy function.
  • Loading branch information
lvnguyen committed Feb 7, 2016
1 parent 3256421 commit edea98f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
23 changes: 21 additions & 2 deletions base/special/bessel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,17 @@ airybiprime(z) = airy(3,z)
airy(k::Number, x::AbstractFloat) = oftype(x, real(airy(k, complex(x))))
airy(k::Number, x::Real) = airy(k, float(x))
airy(k::Number, z::Complex64) = Complex64(airy(k, Complex128(z)))
airy(k::Number, z::Complex) = airy(convert(Int,k), Complex128(z))

function airy{T}(k::Number, z::Complex{T})
if T === BigInt
throw(ArgumentError("Airy is currently not supported for type Complex{BigInt} (see #11512)"))
elseif T == BigFloat
throw(ArgumentError("Airy is currently not supported for type Complex{BigFloat} (see #11512)"))
else
airy(convert(Int,k), Complex128(z))
end
end

@vectorize_2arg Number airy

function airyx(k::Int, z::Complex128)
Expand Down Expand Up @@ -370,7 +380,16 @@ for f in ("i", "ix", "j", "jx", "k", "kx", "y", "yx")
bfn = symbol("bessel", f)
@eval begin
$bfn(nu::Real, z::Complex64) = Complex64($bfn(Float64(nu), Complex128(z)))
$bfn(nu::Real, z::Complex) = $bfn(Float64(nu), Complex128(z))
function $bfn{T}(nu::Real, z::Complex{T})
if T === BigInt
throw(ArgumentError("Bessel is currently not supported for type Complex{BigInt} (see #11512)"))
elseif T === BigFloat
throw(ArgumentError("Bessel is currently not supported for type Complex{BigFloat} (see #11512)"))
else
$bfn(Float64(nu), Complex128(z))
end
end

$bfn(nu::Real, x::Integer) = $bfn(nu, Float64(x))
@vectorize_2arg Number $bfn
end
Expand Down
16 changes: 15 additions & 1 deletion test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ end
@test_throws Base.Math.AmosException airybi(200)
@test_throws ArgumentError airy(5,one(Complex128))
z = 1.8 + 1.0im
for elty in [Complex64,Complex128, Complex{BigFloat}]
for elty in [Complex64,Complex128]
@test_approx_eq airy(convert(elty,1.8)) 0.0470362168668458052247
z = convert(elty,z)
@test_approx_eq airyx(z) airyx(0,z)
Expand All @@ -325,6 +325,11 @@ for elty in [Complex64,Complex128, Complex{BigFloat}]
@test_throws ArgumentError airyx(5,z)
end

@test_throws ArgumentError airy(0, big(1im))
@test_throws ArgumentError airy(0, big(1.0im))
@test_throws ArgumentError airy(1, big(1im))
@test_throws ArgumentError airy(1, big(1.0im))

# bessely0, bessely1, besselj0, besselj1
@test_approx_eq besselj0(Float32(2.0)) besselj0(Float64(2.0))
@test_approx_eq besselj1(Float32(2.0)) besselj1(Float64(2.0))
Expand All @@ -339,6 +344,15 @@ end
@test_approx_eq bessely0(2.0 + im) bessely(0, 2.0 + im)
@test_approx_eq bessely1(2.0 + im) bessely(1, 2.0 + im)

@test_throws ArgumentError besselj0(big(2im))
@test_throws ArgumentError besselj0(big(2.0im))
@test_throws ArgumentError besselj1(big(2im))
@test_throws ArgumentError besselj1(big(2.0im))
@test_throws ArgumentError bessely0(big(2im))
@test_throws ArgumentError bessely0(big(2.0im))
@test_throws ArgumentError bessely1(big(2im))
@test_throws ArgumentError bessely1(big(2.0im))

# besselh
true_h133 = 0.30906272225525164362 - 0.53854161610503161800im
@test_approx_eq besselh(3,1,3) true_h133
Expand Down

0 comments on commit edea98f

Please sign in to comment.