Skip to content

Commit

Permalink
Some fixes and a minor tweak
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 committed Oct 8, 2024
1 parent e2c1ddf commit 0fc9f8e
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))

Check warning on line 1474 in src/calcium/ca.jl

View check run for this annotation

Codecov / codecov/patch

src/calcium/ca.jl#L1473-L1474

Added lines #L1473 - L1474 were not covered by tests
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)

Check warning on line 348 in src/flint/fmpz_mod.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpz_mod.jl#L346-L348

Added lines #L346 - L348 were not covered by tests
else
one!(z.data)

Check warning on line 350 in src/flint/fmpz_mod.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpz_mod.jl#L350

Added line #L350 was not covered by tests
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)

Check warning on line 358 in src/flint/fmpz_mod.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpz_mod.jl#L355-L358

Added lines #L355 - L358 were not covered by tests
else
z.data = sub!(z.data, R.n, a.data)
sub!(z.data, R.n, x.data)

Check warning on line 360 in src/flint/fmpz_mod.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/fmpz_mod.jl#L360

Added line #L360 was not covered by tests
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)

Check warning on line 365 in src/flint/gfp_fmpz_elem.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/gfp_fmpz_elem.jl#L363-L365

Added lines #L363 - L365 were not covered by tests
else
sub!(z.data, R.n, x.data)

Check warning on line 367 in src/flint/gfp_fmpz_elem.jl

View check run for this annotation

Codecov / codecov/patch

src/flint/gfp_fmpz_elem.jl#L367

Added line #L367 was not covered by tests
end
return z
end

Expand Down

0 comments on commit 0fc9f8e

Please sign in to comment.