Skip to content

Commit

Permalink
Some fixes and a minor tweak (#1885)
Browse files Browse the repository at this point in the history
- Better conversion to CalciumField / zzModPolyRing
- Fix neg! for FpFieldElem
- Fix neg! for ZZModRingElem
- Fix one! for ZZModRingElem
  • Loading branch information
fingolfin authored Oct 9, 2024
1 parent e2c1ddf commit ae8c64d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/calcium/ca.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,10 @@ function (C::CalciumField)(v::QQBarFieldElem)
return z
end

function (C::CalciumField)(v::RationalUnion)
return C(flintify(v))
end

# todo: optimize
function (C::CalciumField)(v::Complex{Int})
return C(QQBarFieldElem(v))
Expand Down
9 changes: 2 additions & 7 deletions src/flint/FlintTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -615,13 +615,8 @@ mutable struct zzModPolyRingElem <: PolyRingElem{zzModRingElem}
return z
end

function zzModPolyRingElem(n::UInt, a::Int)
z = new()
ccall((:nmod_poly_init, libflint), Nothing, (Ref{zzModPolyRingElem}, UInt), z, n)
ccall((:nmod_poly_set_coeff_ui, libflint), Nothing,
(Ref{zzModPolyRingElem}, Int, UInt), z, 0, mod(a, n))
finalizer(_nmod_poly_clear_fn, z)
return z
function zzModPolyRingElem(n::UInt, a::Integer)
return zzModPolyRingElem(n, mod(a, n) % UInt)
end

function zzModPolyRingElem(n::UInt, arr::Vector{ZZRingElem})
Expand Down
16 changes: 11 additions & 5 deletions src/flint/fmpz_mod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,21 @@ function zero!(z::ZZModRingElem)
end

function one!(z::ZZModRingElem)
one!(z.data)
R = parent(z)
if R.n == 1
zero!(z.data)
else
one!(z.data)
end
return z
end

function neg!(z::ZZModRingElem, a::ZZModRingElem)
if iszero(a.data)
z.data = zero!(z.data)
function neg!(z::ZZModRingElem, x::ZZModRingElem)
R = parent(z)
if is_zero(x.data)
zero!(z.data)
else
z.data = sub!(z.data, R.n, a.data)
sub!(z.data, R.n, x.data)
end
return z
end
Expand Down
7 changes: 6 additions & 1 deletion src/flint/gfp_fmpz_elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,12 @@ function one!(z::FpFieldElem)
end

function neg!(z::FpFieldElem, x::FpFieldElem)
z.data = R.n - x.data
R = parent(z)
if is_zero(x.data)
zero!(z.data)
else
sub!(z.data, R.n, x.data)
end
return z
end

Expand Down

0 comments on commit ae8c64d

Please sign in to comment.