diff --git a/src/calcium/ca.jl b/src/calcium/ca.jl index 9b6b4af33..2fa2f2325 100644 --- a/src/calcium/ca.jl +++ b/src/calcium/ca.jl @@ -1363,11 +1363,9 @@ end function (::Type{ComplexF64})(x::CalciumFieldElem) z = AcbField(53, cached = false)(x) - x = ArbFieldElem() - ccall((:acb_get_real, libflint), Nothing, (Ref{ArbFieldElem}, Ref{AcbFieldElem}), x, z) + x = real(z) xx = Float64(x) - y = ArbFieldElem() - ccall((:acb_get_imag, libflint), Nothing, (Ref{ArbFieldElem}, Ref{AcbFieldElem}), y, z) + y = imag(z) yy = Float64(y) return ComplexF64(xx, yy) end diff --git a/src/calcium/qqbar.jl b/src/calcium/qqbar.jl index 7c918a0c9..7c6468c8e 100644 --- a/src/calcium/qqbar.jl +++ b/src/calcium/qqbar.jl @@ -1485,16 +1485,21 @@ function ZZRingElem(a::QQBarFieldElem) 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) + z = AcbField(57, cached = false)(x) + x = real(z) xx = Float64(x) - y = ArbFieldElem() - ccall((:acb_get_imag, libflint), Nothing, (Ref{ArbFieldElem}, Ref{AcbFieldElem}), y, z) + y = imag(z) 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) + return Float64(x) +end + ############################################################################### # # Unsafe functions diff --git a/test/calcium/qqbar-test.jl b/test/calcium/qqbar-test.jl index e094b624d..f24a186cb 100644 --- a/test/calcium/qqbar-test.jl +++ b/test/calcium/qqbar-test.jl @@ -400,6 +400,12 @@ end @test contains(ComplexField()(a), ComplexField()(b)) end end + + x = sqrt(R(2)) + @test isapprox(Float64(x), sqrt(2)) + + x = sqrt(R(-2)) + @test_throws InexactError Float64(x) end function test_elem(R::QQBarField)