Skip to content

Commit 78dcd48

Browse files
authored
Update IntegerMathUtils.jl (#20)
* Update IntegerMathUtils.jl fixes #19 * tests
1 parent f1db151 commit 78dcd48

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/IntegerMathUtils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ iroot(x::T, n::Cint) where {T<:Integer} = T(iroot(big(x), Cint(n)))
88

99
function iroot(x::BigInt, n::Cint)
1010
n <= 0 && throw(DomainError(n, "Exponent must be > 0"))
11-
x <= 0 && iseven(x) && throw(DomainError(n, "This is a math no-no"))
11+
x <= 0 && iseven(n) && throw(DomainError(n, "This is a math no-no"))
1212
ans = BigInt()
1313
@ccall :libgmp.__gmpz_root(ans::Ref{BigInt}, x::Ref{BigInt}, n::Cint)::Cint
1414
ans

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ using Test, IntegerMathUtils
1111
@test iroot(T(10000), 4) == T(10)
1212
@test iroot(T(10001), 4) == T(10)
1313
@test iroot(T(9999), 4) == T(9)
14+
@test iroot(T(-8), 3) == T(-2)
15+
@test_throws DomainError iroot(T(-8), 4)
1416
end
1517
@test iroot(big(23)^50, 50) == big(23)
1618
@test iroot(big(23)^50 + 1, 50) == big(23)

0 commit comments

Comments
 (0)