Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some convert method to/from QQBarFieldElem #1963

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/calcium/qqbar.jl
Original file line number Diff line number Diff line change
@@ -1414,6 +1414,17 @@ function (::Type{Float64})(a::QQBarFieldElem)
return Float64(x)
end

function (::Type{T})(a::QQBarFieldElem) where {T <: Integer}
return T(ZZRingElem(a))
end

function (::Type{T})(a::QQBarFieldElem) where {T <: Rational}
return T(QQFieldElem(a))
end

convert(::Type{QQBarFieldElem}, a::RationalUnion) = QQBarFieldElem(a)
convert(::Type{T}, a::QQBarFieldElem) where {T <: RationalUnion} = T(a)

###############################################################################
#
# Unsafe functions
31 changes: 31 additions & 0 deletions test/calcium/qqbar-test.jl
Original file line number Diff line number Diff line change
@@ -418,4 +418,35 @@ end
x = sqrt(R(-2))
@test_throws InexactError Float64(x)
@test isapprox(ComplexF64(x),sqrt(complex(-2)))


x = R(2)
for T in [Int16, UInt32, Int, BigInt, Rational{Int}, Rational{BigInt}, ZZRingElem, QQFieldElem]
y = convert(T, x)
@test y::T == 2

y = T(x)
@test y::T == 2

z = convert(QQBarFieldElem, y)
@test z::QQBarFieldElem == x

z = QQBarFieldElem(y)
@test z::QQBarFieldElem == x
end

x = R(2//3)
for T in [Rational{Int}, Rational{BigInt}, QQFieldElem]
y = convert(T, x)
@test y::T == 2//3

y = T(x)
@test y::T == 2//3

z = convert(QQBarFieldElem, y)
@test z::QQBarFieldElem == x

z = QQBarFieldElem(y)
@test z::QQBarFieldElem == x
end
end