Skip to content

Commit

Permalink
Fix root(RealFieldElem(0), 3) (#1965)
Browse files Browse the repository at this point in the history
Fix root(RealFieldElem(0), 3)
  • Loading branch information
fingolfin authored Dec 11, 2024
1 parent 9964b3e commit ea3fb30
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/arb/Real.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,7 @@ function hypot(x::RealFieldElem, y::RealFieldElem, prec::Int = precision(Balls))
end

function root(x::RealFieldElem, n::UInt, prec::Int = precision(Balls))
is_zero(x) && return x
z = RealFieldElem()
@ccall libflint.arb_root(z::Ref{RealFieldElem}, x::Ref{RealFieldElem}, n::UInt, prec::Int)::Nothing
return z
Expand Down
1 change: 1 addition & 0 deletions src/arb/arb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ function hypot(x::ArbFieldElem, y::ArbFieldElem)
end

function root(x::ArbFieldElem, n::UInt)
is_zero(x) && return x
z = parent(x)()
@ccall libflint.arb_root(z::Ref{ArbFieldElem}, x::Ref{ArbFieldElem}, n::UInt, parent(x).prec::Int)::Nothing
return z
Expand Down
6 changes: 6 additions & 0 deletions test/arb/Real-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ end

@test_throws DomainError root(-x, 3)

a = RR(0)
@testset "root(0, i)" for i in 1:10
@test is_zero(root(a, i))
@test is_zero(root(a, UInt(i)))
end

@test overlaps(factorial(x), RR("0.886581428719259125080918 +/- 6.66e-25"))
@test factorial(UInt(10), RR) == 3628800
@test factorial(Int(10), RR) == 3628800
Expand Down
6 changes: 6 additions & 0 deletions test/arb/arb-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ end

@test_throws DomainError root(-x, 3)

a = RR(0)
@testset "root(0, i)" for i in 1:10
@test is_zero(root(a, i))
@test is_zero(root(a, UInt(i)))
end

@test overlaps(factorial(x), RR("0.886581428719259125080918 +/- 6.66e-25"))
@test factorial(UInt(10), RR) == 3628800
@test factorial(Int(10), RR) == 3628800
Expand Down

0 comments on commit ea3fb30

Please sign in to comment.