diff --git a/src/arb/Complex.jl b/src/arb/Complex.jl index 32370ca05..4f26a1680 100644 --- a/src/arb/Complex.jl +++ b/src/arb/Complex.jl @@ -27,16 +27,9 @@ is_domain_type(::Type{ComplexFieldElem}) = true is_exact_type(::Type{ComplexFieldElem}) = false -function zero(r::ComplexField) - z = ComplexFieldElem() - return z -end +zero(r::ComplexField) = ComplexFieldElem() -function one(r::ComplexField) - z = ComplexFieldElem() - ccall((:acb_one, libflint), Nothing, (Ref{ComplexFieldElem}, ), z) - return z -end +one(r::ComplexField) = one!(ComplexFieldElem()) @doc raw""" onei(r::ComplexField) @@ -45,7 +38,7 @@ Return exact one times $i$ in the given Arb complex field. """ function onei(r::ComplexField) z = ComplexFieldElem() - ccall((:acb_onei, libflint), Nothing, (Ref{ComplexFieldElem}, ), z) + onei!(z) return z end @@ -156,11 +149,7 @@ end # ################################################################################ -function -(x::ComplexFieldElem) - z = ComplexFieldElem() - ccall((:acb_neg, libflint), Nothing, (Ref{ComplexFieldElem}, Ref{ComplexFieldElem}), z, x) - return z -end +-(x::ComplexFieldElem) = neg!(ComplexFieldElem(), x) ################################################################################ # @@ -239,29 +228,25 @@ end function -(x::UInt, y::ComplexFieldElem) z = ComplexFieldElem() ccall((:acb_sub_ui, libflint), Nothing, (Ref{ComplexFieldElem}, Ref{ComplexFieldElem}, UInt, Int), z, y, x, precision(Balls)) - ccall((:acb_neg, libflint), Nothing, (Ref{ComplexFieldElem}, Ref{ComplexFieldElem}), z, z) - return z + return neg!(z) end function -(x::Int, y::ComplexFieldElem) z = ComplexFieldElem() ccall((:acb_sub_si, libflint), Nothing, (Ref{ComplexFieldElem}, Ref{ComplexFieldElem}, Int, Int), z, y, x, precision(Balls)) - ccall((:acb_neg, libflint), Nothing, (Ref{ComplexFieldElem}, Ref{ComplexFieldElem}), z, z) - return z + return neg!(z) end function -(x::ZZRingElem, y::ComplexFieldElem) z = ComplexFieldElem() ccall((:acb_sub_fmpz, libflint), Nothing, (Ref{ComplexFieldElem}, Ref{ComplexFieldElem}, Ref{ZZRingElem}, Int), z, y, x, precision(Balls)) - ccall((:acb_neg, libflint), Nothing, (Ref{ComplexFieldElem}, Ref{ComplexFieldElem}), z, z) - return z + return neg!(z) end function -(x::RealFieldElem, y::ComplexFieldElem) z = ComplexFieldElem() ccall((:acb_sub_arb, libflint), Nothing, (Ref{ComplexFieldElem}, Ref{ComplexFieldElem}, Ref{RealFieldElem}, Int), z, y, x, precision(Balls)) - ccall((:acb_neg, libflint), Nothing, (Ref{ComplexFieldElem}, Ref{ComplexFieldElem}), z, z) - return z + return neg!(z) end +(x::ComplexFieldElem, y::Integer) = x + flintify(y) @@ -1581,13 +1566,23 @@ end # ################################################################################ -function zero!(z::ComplexFieldElem) - ccall((:acb_zero, libflint), Nothing, (Ref{ComplexFieldElem},), z) +function zero!(z::ComplexFieldElemOrPtr) + @ccall libflint.acb_zero(z::Ref{ComplexFieldElem})::Nothing + return z +end + +function one!(z::ComplexFieldElemOrPtr) + @ccall libflint.acb_one(z::Ref{ComplexFieldElem})::Nothing + return z +end + +function onei!(z::ComplexFieldElemOrPtr) + @ccall libflint.acb_onei(z::Ref{ComplexFieldElem})::Nothing return z end -function one!(z::ComplexFieldElem) - ccall((:acb_one, libflint), Nothing, (Ref{ComplexFieldElem},), z) +function neg!(z::ComplexFieldElemOrPtr, a::ComplexFieldElemOrPtr) + @ccall libflint.acb_neg(z::Ref{ComplexFieldElem}, a::Ref{ComplexFieldElem})::Nothing return z end @@ -1675,21 +1670,21 @@ for (typeofx, passtoc) in ((ComplexFieldElem, Ref{ComplexFieldElem}), (Ptr{Compl r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) _arb_set(r, y, p) i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - ccall((:arb_zero, libflint), Nothing, (Ptr{RealFieldElem}, ), i) + zero!(i) end function _acb_set(x::($typeofx), y::BigFloat) r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) _arb_set(r, y) i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - ccall((:arb_zero, libflint), Nothing, (Ptr{RealFieldElem}, ), i) + zero!(i) end function _acb_set(x::($typeofx), y::BigFloat, p::Int) r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) _arb_set(r, y, p) i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - ccall((:arb_zero, libflint), Nothing, (Ptr{RealFieldElem}, ), i) + zero!(i) end function _acb_set(x::($typeofx), y::Int, z::Int, p::Int) @@ -1728,7 +1723,7 @@ for (typeofx, passtoc) in ((ComplexFieldElem, Ref{ComplexFieldElem}), (Ptr{Compl r = ccall((:acb_real_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) _arb_set(r, y, p) i = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (($passtoc), ), x) - ccall((:arb_zero, libflint), Nothing, (Ptr{ArbFieldElem}, ), i) + zero!(i) end function _acb_set(x::($typeofx), y::Complex, p::Int) diff --git a/src/arb/ComplexMat.jl b/src/arb/ComplexMat.jl index add2973ad..2fe4be9a3 100644 --- a/src/arb/ComplexMat.jl +++ b/src/arb/ComplexMat.jl @@ -80,9 +80,7 @@ setindex!(x::ComplexMatrix, y::Tuple{Rational{T}, Rational{T}}, r::Int, c::Int) setindex!(x, map(QQFieldElem, y), r, c) function one(x::ComplexMatrixSpace) - z = x() - ccall((:acb_mat_one, libflint), Nothing, (Ref{ComplexMatrix}, ), z) - return z + return one!(x()) end number_of_rows(a::ComplexMatrix) = a.r @@ -101,11 +99,7 @@ end # ################################################################################ -function -(x::ComplexMatrix) - z = similar(x) - ccall((:acb_mat_neg, libflint), Nothing, (Ref{ComplexMatrix}, Ref{ComplexMatrix}), z, x) - return z -end +-(x::ComplexMatrix) = neg!(similar(x), x) ################################################################################ # @@ -723,6 +717,21 @@ end # ################################################################################ +function zero!(z::ComplexMatrixOrPtr) + @ccall libflint.acb_mat_zero(z::Ref{ComplexMatrix})::Nothing + return z +end + +function one!(z::ComplexMatrixOrPtr) + @ccall libflint.acb_mat_one(z::Ref{ComplexMatrix})::Nothing + return z +end + +function neg!(z::ComplexMatrixOrPtr, a::ComplexMatrixOrPtr) + @ccall libflint.acb_mat_neg(z::Ref{ComplexMatrix}, a::Ref{ComplexMatrix})::Nothing + return z +end + for (s,f) in (("add!","acb_mat_add"), ("mul!","acb_mat_mul"), ("sub!","acb_mat_sub")) @eval begin @@ -893,9 +902,7 @@ function identity_matrix(R::ComplexField, n::Int) if n < 0 error("dimension must not be negative") end - z = ComplexMatrix(n, n) - ccall((:acb_mat_one, libflint), Nothing, (Ref{ComplexMatrix}, ), z) - return z + return one!(ComplexMatrix(n, n)) end ################################################################################ diff --git a/src/arb/ComplexPoly.jl b/src/arb/ComplexPoly.jl index d6d1270e9..a6983aabf 100644 --- a/src/arb/ComplexPoly.jl +++ b/src/arb/ComplexPoly.jl @@ -224,11 +224,7 @@ end # ################################################################################ -function -(x::ComplexPolyRingElem) - z = parent(x)() - ccall((:acb_poly_neg, libflint), Nothing, (Ref{ComplexPolyRingElem}, Ref{ComplexPolyRingElem}), z, x) - return z -end +-(x::ComplexPolyRingElem) = neg!(parent(x)(), x) ################################################################################ # @@ -635,10 +631,10 @@ function roots(x::ComplexPolyRingElem; target=0, isolate_real=false, initial_pre if real_ok for i = 0 : deg - 1 - im = ccall((:acb_imag_ptr, libflint), Ptr{arb_struct}, + im = ccall((:acb_imag_ptr, libflint), Ptr{RealFieldElem}, (Ptr{ComplexFieldElem}, ), roots + i * sizeof(acb_struct)) - if ccall((:arb_contains_zero, libflint), Bool, (Ptr{arb_struct}, ), im) - ccall((:arb_zero, libflint), Nothing, (Ptr{arb_struct}, ), im) + if ccall((:arb_contains_zero, libflint), Bool, (Ptr{RealFieldElem}, ), im) + zero!(im) end end end @@ -702,13 +698,18 @@ end # ############################################################################### -function zero!(z::ComplexPolyRingElem) - ccall((:acb_poly_zero, libflint), Nothing, (Ref{ComplexPolyRingElem},), z) +function zero!(z::ComplexPolyRingElemOrPtr) + @ccall libflint.acb_poly_zero(z::Ref{ComplexPolyRingElem})::Nothing + return z +end + +function one!(z::ComplexPolyRingElemOrPtr) + @ccall libflint.acb_poly_one(z::Ref{ComplexPolyRingElem})::Nothing return z end -function one!(z::ComplexPolyRingElem) - ccall((:acb_poly_one, libflint), Nothing, (Ref{ComplexPolyRingElem},), z) +function neg!(z::ComplexPolyRingElemOrPtr, a::ComplexPolyRingElemOrPtr) + @ccall libflint.acb_poly_neg(z::Ref{ComplexPolyRingElem}, a::Ref{ComplexPolyRingElem})::Nothing return z end diff --git a/src/arb/Real.jl b/src/arb/Real.jl index 6e72c3eb6..6f1012a2a 100644 --- a/src/arb/Real.jl +++ b/src/arb/Real.jl @@ -586,11 +586,7 @@ end # ################################################################################ -function -(x::RealFieldElem) - z = RealFieldElem() - ccall((:arb_neg, libflint), Nothing, (Ref{RealFieldElem}, Ref{RealFieldElem}), z, x) - return z -end +-(x::RealFieldElem) = neg!(RealFieldElem(), x) ################################################################################ # @@ -1929,20 +1925,25 @@ end # ################################################################################ -function zero!(z::RealFieldElem) - ccall((:arb_zero, libflint), Nothing, (Ref{RealFieldElem},), z) +function zero!(z::RealFieldElemOrPtr) + @ccall libflint.arb_zero(z::Ref{RealFieldElem})::Nothing + return z +end + +function one!(z::RealFieldElemOrPtr) + @ccall libflint.arb_one(z::Ref{RealFieldElem})::Nothing return z end -function one!(z::RealFieldElem) - ccall((:arb_one, libflint), Nothing, (Ref{RealFieldElem},), z) +function neg!(z::RealFieldElemOrPtr, a::RealFieldElemOrPtr) + @ccall libflint.arb_neg(z::Ref{RealFieldElem}, a::Ref{RealFieldElem})::Nothing return z end for (s,f) in (("add!","arb_add"), ("mul!","arb_mul"), ("div!", "arb_div"), ("sub!","arb_sub")) @eval begin - function ($(Symbol(s)))(z::RealFieldElem, x::RealFieldElem, y::RealFieldElem, prec::Int = precision(Balls)) + function ($(Symbol(s)))(z::RealFieldElemOrPtr, x::RealFieldElemOrPtr, y::RealFieldElemOrPtr, prec::Int = precision(Balls)) ccall(($f, libflint), Nothing, (Ref{RealFieldElem}, Ref{RealFieldElem}, Ref{RealFieldElem}, Int), z, x, y, prec) return z diff --git a/src/arb/RealMat.jl b/src/arb/RealMat.jl index e8efd1104..5796bdd5f 100644 --- a/src/arb/RealMat.jl +++ b/src/arb/RealMat.jl @@ -68,9 +68,7 @@ Base.@propagate_inbounds setindex!(x::RealMatrix, y::Rational{T}, setindex!(x, ZZRingElem(y), r, c) function one(x::RealMatrixSpace) - z = x() - ccall((:arb_mat_one, libflint), Nothing, (Ref{RealMatrix}, ), z) - return z + return one!(x()) end number_of_rows(a::RealMatrix) = a.r @@ -89,11 +87,7 @@ end # ################################################################################ -function -(x::RealMatrix) - z = similar(x) - ccall((:arb_mat_neg, libflint), Nothing, (Ref{RealMatrix}, Ref{RealMatrix}), z, x) - return z -end +-(x::RealMatrix) = neg!(similar(x), x) ################################################################################ # @@ -665,6 +659,21 @@ end # ################################################################################ +function zero!(z::RealMatrixOrPtr) + @ccall libflint.arb_mat_zero(z::Ref{RealMatrix})::Nothing + return z +end + +function one!(z::RealMatrixOrPtr) + @ccall libflint.arb_mat_one(z::Ref{RealMatrix})::Nothing + return z +end + +function neg!(z::RealMatrixOrPtr, a::RealMatrixOrPtr) + @ccall libflint.arb_mat_neg(z::Ref{RealMatrix}, a::Ref{RealMatrix})::Nothing + return z +end + for (s,f) in (("add!","arb_mat_add"), ("mul!","arb_mat_mul"), ("sub!","arb_mat_sub")) @eval begin @@ -783,9 +792,7 @@ function identity_matrix(R::RealField, n::Int) if n < 0 error("dimension must not be negative") end - z = RealMatrix(n, n) - ccall((:arb_mat_one, libflint), Nothing, (Ref{RealMatrix}, ), z) - return z + return one!(RealMatrix(n, n)) end ############################################################################### diff --git a/src/arb/RealPoly.jl b/src/arb/RealPoly.jl index f67c48c5a..191a6a25d 100644 --- a/src/arb/RealPoly.jl +++ b/src/arb/RealPoly.jl @@ -210,11 +210,7 @@ end # ################################################################################ -function -(x::RealPolyRingElem) - z = parent(x)() - ccall((:arb_poly_neg, libflint), Nothing, (Ref{RealPolyRingElem}, Ref{RealPolyRingElem}), z, x) - return z -end +-(x::RealPolyRingElem) = neg!(parent(x)(), x) ################################################################################ # @@ -601,15 +597,18 @@ end # ############################################################################### -function zero!(z::RealPolyRingElem) - ccall((:arb_poly_zero, libflint), Nothing, - (Ref{RealPolyRingElem}, ), z) +function zero!(z::RealPolyRingElemOrPtr) + @ccall libflint.arb_poly_zero(z::Ref{RealPolyRingElem})::Nothing + return z +end + +function one!(z::RealPolyRingElemOrPtr) + @ccall libflint.arb_poly_one(z::Ref{RealPolyRingElem})::Nothing return z end -function one!(z::RealPolyRingElem) - ccall((:arb_poly_one, libflint), Nothing, - (Ref{RealPolyRingElem}, ), z) +function neg!(z::RealPolyRingElemOrPtr, a::RealPolyRingElemOrPtr) + @ccall libflint.arb_poly_neg(z::Ref{RealPolyRingElem}, a::Ref{RealPolyRingElem})::Nothing return z end diff --git a/src/arb/acb.jl b/src/arb/acb.jl index 5e8632c6d..a0e33edec 100644 --- a/src/arb/acb.jl +++ b/src/arb/acb.jl @@ -35,7 +35,7 @@ end function one(r::AcbField) z = AcbFieldElem() - ccall((:acb_one, libflint), Nothing, (Ref{AcbFieldElem}, ), z) + one!(z) z.parent = r return z end @@ -47,7 +47,7 @@ Return exact one times $i$ in the given Arb complex field. """ function onei(r::AcbField) z = AcbFieldElem() - ccall((:acb_onei, libflint), Nothing, (Ref{AcbFieldElem}, ), z) + onei!(z) z.parent = r return z end @@ -160,11 +160,7 @@ end # ################################################################################ -function -(x::AcbFieldElem) - z = parent(x)() - ccall((:acb_neg, libflint), Nothing, (Ref{AcbFieldElem}, Ref{AcbFieldElem}), z, x) - return z -end +-(x::AcbFieldElem) = neg!(parent(x)(), x) ################################################################################ # @@ -243,29 +239,25 @@ end function -(x::UInt, y::AcbFieldElem) z = parent(y)() ccall((:acb_sub_ui, libflint), Nothing, (Ref{AcbFieldElem}, Ref{AcbFieldElem}, UInt, Int), z, y, x, parent(y).prec) - ccall((:acb_neg, libflint), Nothing, (Ref{AcbFieldElem}, Ref{AcbFieldElem}), z, z) - return z + return neg!(z) end function -(x::Int, y::AcbFieldElem) z = parent(y)() ccall((:acb_sub_si, libflint), Nothing, (Ref{AcbFieldElem}, Ref{AcbFieldElem}, Int, Int), z, y, x, parent(y).prec) - ccall((:acb_neg, libflint), Nothing, (Ref{AcbFieldElem}, Ref{AcbFieldElem}), z, z) - return z + return neg!(z) end function -(x::ZZRingElem, y::AcbFieldElem) z = parent(y)() ccall((:acb_sub_fmpz, libflint), Nothing, (Ref{AcbFieldElem}, Ref{AcbFieldElem}, Ref{ZZRingElem}, Int), z, y, x, parent(y).prec) - ccall((:acb_neg, libflint), Nothing, (Ref{AcbFieldElem}, Ref{AcbFieldElem}), z, z) - return z + return neg!(z) end function -(x::ArbFieldElem, y::AcbFieldElem) z = parent(y)() ccall((:acb_sub_arb, libflint), Nothing, (Ref{AcbFieldElem}, Ref{AcbFieldElem}, Ref{ArbFieldElem}, Int), z, y, x, parent(y).prec) - ccall((:acb_neg, libflint), Nothing, (Ref{AcbFieldElem}, Ref{AcbFieldElem}), z, z) - return z + return neg!(z) end +(x::AcbFieldElem, y::Integer) = x + ZZRingElem(y) @@ -1569,13 +1561,23 @@ end # ################################################################################ -function zero!(z::AcbFieldElem) - ccall((:acb_zero, libflint), Nothing, (Ref{AcbFieldElem},), z) +function zero!(z::AcbFieldElemOrPtr) + @ccall libflint.acb_zero(z::Ref{AcbFieldElem})::Nothing + return z +end + +function one!(z::AcbFieldElemOrPtr) + @ccall libflint.acb_one(z::Ref{AcbFieldElem})::Nothing + return z +end + +function onei!(z::AcbFieldElemOrPtr) + @ccall libflint.acb_onei(z::Ref{AcbFieldElem})::Nothing return z end -function one!(z::AcbFieldElem) - ccall((:acb_one, libflint), Nothing, (Ref{AcbFieldElem},), z) +function neg!(z::AcbFieldElemOrPtr, a::AcbFieldElemOrPtr) + @ccall libflint.acb_neg(z::Ref{AcbFieldElem}, a::Ref{AcbFieldElem})::Nothing return z end @@ -1663,21 +1665,21 @@ for (typeofx, passtoc) in ((AcbFieldElem, Ref{AcbFieldElem}), (Ptr{AcbFieldElem} r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) _arb_set(r, y, p) i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - ccall((:arb_zero, libflint), Nothing, (Ptr{ArbFieldElem}, ), i) + zero!(i) end function _acb_set(x::($typeofx), y::BigFloat) r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) _arb_set(r, y) i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - ccall((:arb_zero, libflint), Nothing, (Ptr{ArbFieldElem}, ), i) + zero!(i) end function _acb_set(x::($typeofx), y::BigFloat, p::Int) r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) _arb_set(r, y, p) i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - ccall((:arb_zero, libflint), Nothing, (Ptr{ArbFieldElem}, ), i) + zero!(i) end function _acb_set(x::($typeofx), y::Int, z::Int, p::Int) @@ -1716,7 +1718,7 @@ for (typeofx, passtoc) in ((AcbFieldElem, Ref{AcbFieldElem}), (Ptr{AcbFieldElem} r = ccall((:acb_real_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) _arb_set(r, y, p) i = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (($passtoc), ), x) - ccall((:arb_zero, libflint), Nothing, (Ptr{ArbFieldElem}, ), i) + zero!(i) end function _acb_set(x::($typeofx), y::Complex, p::Int) diff --git a/src/arb/acb_mat.jl b/src/arb/acb_mat.jl index 47fbaf416..925442d07 100644 --- a/src/arb/acb_mat.jl +++ b/src/arb/acb_mat.jl @@ -83,9 +83,7 @@ setindex!(x::AcbMatrix, y::Tuple{Rational{T}, Rational{T}}, r::Int, c::Int) wher setindex!(x, map(QQFieldElem, y), r, c) function one(x::AcbMatrixSpace) - z = x() - ccall((:acb_mat_one, libflint), Nothing, (Ref{AcbMatrix}, ), z) - return z + return one!(x()) end number_of_rows(a::AcbMatrix) = a.r @@ -104,11 +102,7 @@ end # ################################################################################ -function -(x::AcbMatrix) - z = similar(x) - ccall((:acb_mat_neg, libflint), Nothing, (Ref{AcbMatrix}, Ref{AcbMatrix}), z, x) - return z -end +-(x::AcbMatrix)= neg!(similar(x), x) ################################################################################ # @@ -725,6 +719,21 @@ end # ################################################################################ +function zero!(z::AcbMatrixOrPtr) + @ccall libflint.acb_mat_zero(z::Ref{AcbMatrix})::Nothing + return z +end + +function one!(z::AcbMatrixOrPtr) + @ccall libflint.acb_mat_one(z::Ref{AcbMatrix})::Nothing + return z +end + +function neg!(z::AcbMatrix, a::AcbMatrixOrPtr) + @ccall libflint.acb_mat_neg(z::Ref{AcbMatrix}, a::Ref{AcbMatrix})::Nothing + return z +end + for (s,f) in (("add!","acb_mat_add"), ("mul!","acb_mat_mul"), ("sub!","acb_mat_sub")) @eval begin @@ -905,8 +914,7 @@ function identity_matrix(R::AcbField, n::Int) if n < 0 error("dimension must not be negative") end - z = AcbMatrix(n, n) - ccall((:acb_mat_one, libflint), Nothing, (Ref{AcbMatrix}, ), z) + z = one!(AcbMatrix(n, n)) z.base_ring = R return z end diff --git a/src/arb/acb_poly.jl b/src/arb/acb_poly.jl index 4256e1564..bc28e7ff8 100644 --- a/src/arb/acb_poly.jl +++ b/src/arb/acb_poly.jl @@ -233,11 +233,7 @@ end # ################################################################################ -function -(x::AcbPolyRingElem) - z = parent(x)() - ccall((:acb_poly_neg, libflint), Nothing, (Ref{AcbPolyRingElem}, Ref{AcbPolyRingElem}), z, x) - return z -end +-(x::AcbPolyRingElem) = neg!(parent(x)(), x) ################################################################################ # @@ -630,10 +626,10 @@ function roots(x::AcbPolyRingElem; target=0, isolate_real=false, initial_prec=0, if real_ok for i = 0 : deg - 1 - im = ccall((:acb_imag_ptr, libflint), Ptr{arb_struct}, + im = ccall((:acb_imag_ptr, libflint), Ptr{ArbFieldElem}, (Ptr{AcbFieldElem}, ), roots + i * sizeof(acb_struct)) - if ccall((:arb_contains_zero, libflint), Bool, (Ptr{arb_struct}, ), im) - ccall((:arb_zero, libflint), Nothing, (Ptr{arb_struct}, ), im) + if ccall((:arb_contains_zero, libflint), Bool, (Ptr{ArbFieldElem}, ), im) + zero!(im) end end end @@ -697,13 +693,18 @@ end # ############################################################################### -function zero!(z::AcbPolyRingElem) - ccall((:acb_poly_zero, libflint), Nothing, (Ref{AcbPolyRingElem},), z) +function zero!(z::AcbPolyRingElemOrPtr) + @ccall libflint.acb_poly_zero(z::Ref{AcbPolyRingElem})::Nothing + return z +end + +function one!(z::AcbPolyRingElemOrPtr) + @ccall libflint.acb_poly_one(z::Ref{AcbPolyRingElem})::Nothing return z end -function one!(z::AcbPolyRingElem) - ccall((:acb_poly_one, libflint), Nothing, (Ref{AcbPolyRingElem},), z) +function neg!(z::AcbPolyRingElemOrPtr, a::AcbPolyRingElemOrPtr) + @ccall libflint.acb_poly_neg(z::Ref{AcbPolyRingElem}, a::Ref{AcbPolyRingElem})::Nothing return z end diff --git a/src/arb/arb.jl b/src/arb/arb.jl index a494dcd0a..5f64190db 100644 --- a/src/arb/arb.jl +++ b/src/arb/arb.jl @@ -625,11 +625,7 @@ Base.signbit(x::ArbFieldElem) = signbit(sign(Int, x)) # ################################################################################ -function -(x::ArbFieldElem) - z = parent(x)() - ccall((:arb_neg, libflint), Nothing, (Ref{ArbFieldElem}, Ref{ArbFieldElem}), z, x) - return z -end +-(x::ArbFieldElem) = neg!(parent(x)(), x) ################################################################################ # @@ -1931,13 +1927,18 @@ end # ################################################################################ -function zero!(z::ArbFieldElem) - ccall((:arb_zero, libflint), Nothing, (Ref{ArbFieldElem},), z) +function zero!(z::Union{ArbFieldElemOrPtr}) + @ccall libflint.arb_zero(z::Ref{ArbFieldElem})::Nothing + return z +end + +function one!(z::ArbFieldElemOrPtr) + @ccall libflint.arb_one(z::Ref{ArbFieldElem})::Nothing return z end -function one!(z::ArbFieldElem) - ccall((:arb_one, libflint), Nothing, (Ref{ArbFieldElem},), z) +function neg!(z::ArbFieldElemOrPtr, a::ArbFieldElemOrPtr) + @ccall libflint.arb_neg(z::Ref{ArbFieldElem}, a::Ref{ArbFieldElem})::Nothing return z end diff --git a/src/arb/arb_mat.jl b/src/arb/arb_mat.jl index aed33f313..bc934c458 100644 --- a/src/arb/arb_mat.jl +++ b/src/arb/arb_mat.jl @@ -71,9 +71,7 @@ Base.@propagate_inbounds setindex!(x::ArbMatrix, y::Rational{T}, setindex!(x, ZZRingElem(y), r, c) function one(x::ArbMatrixSpace) - z = x() - ccall((:arb_mat_one, libflint), Nothing, (Ref{ArbMatrix}, ), z) - return z + return one!(x()) end number_of_rows(a::ArbMatrix) = a.r @@ -93,11 +91,7 @@ end # ################################################################################ -function -(x::ArbMatrix) - z = similar(x) - ccall((:arb_mat_neg, libflint), Nothing, (Ref{ArbMatrix}, Ref{ArbMatrix}), z, x) - return z -end +-(x::ArbMatrix) = neg!(similar(x), x) ################################################################################ # @@ -692,6 +686,21 @@ end # ################################################################################ +function zero!(z::ArbMatrixOrPtr) + @ccall libflint.arb_mat_zero(z::Ref{ArbMatrix})::Nothing + return z +end + +function one!(z::ArbMatrixOrPtr) + @ccall libflint.arb_mat_one(z::Ref{ArbMatrix})::Nothing + return z +end + +function neg!(z::ArbMatrixOrPtr, a::ArbMatrixOrPtr) + @ccall libflint.arb_mat_neg(z::Ref{ArbMatrix}, a::Ref{ArbMatrix})::Nothing + return z +end + for (s,f) in (("add!","arb_mat_add"), ("mul!","arb_mat_mul"), ("sub!","arb_mat_sub")) @eval begin @@ -802,8 +811,7 @@ function identity_matrix(R::ArbField, n::Int) if n < 0 error("dimension must not be negative") end - z = ArbMatrix(n, n) - ccall((:arb_mat_one, libflint), Nothing, (Ref{ArbMatrix}, ), z) + z = one!(ArbMatrix(n, n)) z.base_ring = R return z end diff --git a/src/arb/arb_poly.jl b/src/arb/arb_poly.jl index 75f0d1f8f..4f14a510b 100644 --- a/src/arb/arb_poly.jl +++ b/src/arb/arb_poly.jl @@ -225,11 +225,7 @@ end # ################################################################################ -function -(x::ArbPolyRingElem) - z = parent(x)() - ccall((:arb_poly_neg, libflint), Nothing, (Ref{ArbPolyRingElem}, Ref{ArbPolyRingElem}), z, x) - return z -end +-(x::ArbPolyRingElem) = neg!(parent(x)(), x) ################################################################################ # @@ -601,15 +597,18 @@ end # ############################################################################### -function zero!(z::ArbPolyRingElem) - ccall((:arb_poly_zero, libflint), Nothing, - (Ref{ArbPolyRingElem}, ), z) +function zero!(z::ArbPolyRingElemOrPtr) + @ccall libflint.arb_poly_zero(z::Ref{ArbPolyRingElem})::Nothing + return z +end + +function one!(z::ArbPolyRingElemOrPtr) + @ccall libflint.arb_poly_one(z::Ref{ArbPolyRingElem})::Nothing return z end -function one!(z::ArbPolyRingElem) - ccall((:arb_poly_one, libflint), Nothing, - (Ref{ArbPolyRingElem}, ), z) +function neg!(z::ArbPolyRingElemOrPtr, a::ArbPolyRingElemOrPtr) + @ccall libflint.arb_poly_neg(z::Ref{ArbPolyRingElem}, a::Ref{ArbPolyRingElem})::Nothing return z end