Skip to content

Commit

Permalink
Galois coerce QQ (#1149)
Browse files Browse the repository at this point in the history
* Add coercion from fmpq to GaloisField.
  • Loading branch information
wbhart authored Sep 6, 2021
1 parent aecb0b6 commit 5b37f25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/flint/gfp_elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,19 @@ function (R::GaloisField)(a::fmpz)
return gfp_elem(d, R)
end

function (R::GaloisField)(a::fmpq)
num = numerator(a, false)
den = denominator(a, false)
n = ccall((:fmpz_fdiv_ui, libflint), UInt, (Ref{fmpz}, UInt),
num, R.n)
d = ccall((:fmpz_fdiv_ui, libflint), UInt, (Ref{fmpz}, UInt),
den, R.n)
V = [UInt(0)]
g = ccall((:n_gcdinv, libflint), UInt, (Ptr{UInt}, UInt, UInt), V, d, R.n)
g != 1 && error("Unable to coerce")
return R(n)*R(V[1])
end

function (R::GaloisField)(a::gfp_elem)
return a
end
Expand Down
4 changes: 4 additions & 0 deletions test/flint/gfp-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

@test isa(R(a), Nemo.gfp_elem)

@test isa(R(fmpq(7, 11)), Nemo.gfp_elem)
@test R(fmpq(7, 11))*11 == 7
@test_throws ErrorException R(fmpq(7, 13))

for i = 1:1000
p = rand(UInt(1):typemax(UInt))

Expand Down

0 comments on commit 5b37f25

Please sign in to comment.