diff --git a/src/IntegerMathUtils.jl b/src/IntegerMathUtils.jl index b7b3e30..136b63f 100644 --- a/src/IntegerMathUtils.jl +++ b/src/IntegerMathUtils.jl @@ -8,7 +8,7 @@ iroot(x::T, n::Cint) where {T<:Integer} = T(iroot(big(x), Cint(n))) function iroot(x::BigInt, n::Cint) n <= 0 && throw(DomainError(n, "Exponent must be > 0")) - x <= 0 && iseven(x) && throw(DomainError(n, "This is a math no-no")) + x <= 0 && iseven(n) && throw(DomainError(n, "This is a math no-no")) ans = BigInt() @ccall :libgmp.__gmpz_root(ans::Ref{BigInt}, x::Ref{BigInt}, n::Cint)::Cint ans diff --git a/test/runtests.jl b/test/runtests.jl index 1ff7da7..a945ba2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,6 +11,8 @@ using Test, IntegerMathUtils @test iroot(T(10000), 4) == T(10) @test iroot(T(10001), 4) == T(10) @test iroot(T(9999), 4) == T(9) + @test iroot(T(-8), 3) == T(-2) + @test_throws DomainError iroot(T(-8), 4) end @test iroot(big(23)^50, 50) == big(23) @test iroot(big(23)^50 + 1, 50) == big(23)