Skip to content

Commit

Permalink
feat: add conversion from QQBarFieldElem to ComplexF64 (#1892)
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma authored Oct 12, 2024
1 parent df3ab65 commit 8fac1af
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/calcium/qqbar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,17 @@ function ZZRingElem(a::QQBarFieldElem)
return z
end

function (::Type{ComplexF64})(x::QQBarFieldElem)
z = AcbField(53, cached = false)(x)
x = ArbFieldElem()
ccall((:acb_get_real, libflint), Nothing, (Ref{ArbFieldElem}, Ref{AcbFieldElem}), x, z)
xx = Float64(x)
y = ArbFieldElem()
ccall((:acb_get_imag, libflint), Nothing, (Ref{ArbFieldElem}, Ref{AcbFieldElem}), y, z)
yy = Float64(y)
return ComplexF64(xx, yy)
end

###############################################################################
#
# Unsafe functions
Expand Down
13 changes: 13 additions & 0 deletions test/calcium/qqbar-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,19 @@ end

end

@testset "QQBarFieldElem.conversions" begin
R = algebraic_closure(QQ)

# precision must be < 53, otherwise the test is wrong
set_precision!(Balls, 50) do
for i in 1:10
a = rand(R, degree=5, bits=5)
b = ComplexF64(a)
@test contains(ComplexField()(a), ComplexField()(b))
end
end
end

function test_elem(R::QQBarField)
return rand(R, degree=5, bits=5)
end
Expand Down

0 comments on commit 8fac1af

Please sign in to comment.