Skip to content

Commit

Permalink
Improve coercion from QQBarFieldElem to RealField/ComplexField
Browse files Browse the repository at this point in the history
Now the precision can be specified as an argument
  • Loading branch information
fingolfin committed Oct 15, 2024
1 parent 39399df commit 3c40528
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/calcium/qqbar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1423,13 +1423,12 @@ function (R::AcbField)(a::QQBarFieldElem)
end

@doc raw"""
(R::RealField)(a::QQBarFieldElem)
(R::RealField)(a::QQBarFieldElem, prec::Int = precision(Balls))
Convert `a` to a real ball with the precision of the parent field `R`.
Convert `a` to a real ball with the given precision.
Throws if `a` is not a real number.
"""
function (R::RealField)(a::QQBarFieldElem)
prec = precision(Balls)
function (R::RealField)(a::QQBarFieldElem, prec::Int = precision(Balls))
z = R()
ccall((:qqbar_get_arb, libflint),
Nothing, (Ref{RealFieldElem}, Ref{QQBarFieldElem}, Int), z, a, prec)
Expand All @@ -1438,12 +1437,11 @@ function (R::RealField)(a::QQBarFieldElem)
end

@doc raw"""
(R::ComplexField)(a::QQBarFieldElem)
(R::ComplexField)(a::QQBarFieldElem, prec::Int = precision(Balls))
Convert `a` to a complex ball with the precision of the parent field `R`.
Convert `a` to a complex ball with the given precision.
"""
function (R::ComplexField)(a::QQBarFieldElem)
prec = precision(Balls)
function (R::ComplexField)(a::QQBarFieldElem, prec::Int = precision(Balls))
z = R()
ccall((:qqbar_get_acb, libflint),
Nothing, (Ref{ComplexFieldElem}, Ref{QQBarFieldElem}, Int), z, a, prec)
Expand Down Expand Up @@ -1485,18 +1483,18 @@ function ZZRingElem(a::QQBarFieldElem)
end

function (::Type{ComplexF64})(x::QQBarFieldElem)
z = AcbField(57, cached = false)(x)
x = real(z)
z = ComplexField()(x)
x = real(z; prec=57)
xx = Float64(x)
y = imag(z)
y = imag(z; prec=57)
yy = Float64(y)
return ComplexF64(xx, yy)
end

function (::Type{Float64})(x::QQBarFieldElem)
isreal(x) || throw(InexactError(:Float64, Float64, x))
z = AcbField(57, cached = false)(x)
x = real(z)
z = ComplexField()(x)
x = real(z; prec=57)
return Float64(x)
end

Expand Down

0 comments on commit 3c40528

Please sign in to comment.