Skip to content

Commit

Permalink
add gaussian numbers ZZi and QQi
Browse files Browse the repository at this point in the history
  • Loading branch information
tthsqe12 committed Sep 8, 2021
1 parent 6344600 commit cbaba03
Show file tree
Hide file tree
Showing 7 changed files with 915 additions and 942 deletions.
36 changes: 19 additions & 17 deletions src/flint/fmpq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -850,23 +850,6 @@ end

add!(c::fmpq, a::Int, b::fmpq) = add!(c, b, a)

###############################################################################
#
# Conversions to/from flint Julia rationals
#
###############################################################################

function Rational(z::fmpq)
r = Rational{BigInt}(0)
ccall((:fmpq_get_mpz_frac, libflint), Nothing,
(Ref{BigInt}, Ref{BigInt}, Ref{fmpq}), r.num, r.den, z)
return r
end

function Rational(z::fmpz)
return Rational{BigInt}(BigInt(z))
end

###############################################################################
#
# Parent object call overloads
Expand Down Expand Up @@ -939,8 +922,27 @@ promote_rule(::Type{fmpq}, ::Type{fmpz}) = fmpq

Base.promote_rule(::Type{fmpq}, ::Type{Rational{T}}) where {T <: Integer} = fmpq

function Base.convert(::Type{Rational{T}}, a::fmpq) where T <: Integer
return Rational{T}(convert(T, numerator(a)), convert(T, denominator(a)))
end

function Base.convert(::Type{fmpq}, a::Rational{T}) where T <: Integer
return convert(fmpz, numerator(a))//convert(fmpz, denominator(a))
end

convert(::Type{Rational{BigInt}}, a::fmpq) = Rational(a)

function Rational(z::fmpq)
r = Rational{BigInt}(0)
ccall((:fmpq_get_mpz_frac, libflint), Nothing,
(Ref{BigInt}, Ref{BigInt}, Ref{fmpq}), r.num, r.den, z)
return r
end

function Rational(z::fmpz)
return Rational{BigInt}(BigInt(z))
end

###############################################################################
#
# FractionField constructor
Expand Down
130 changes: 113 additions & 17 deletions src/flint/fmpz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,98 @@ end
#
###############################################################################

function zero!(z::fmpz)
ccall((:fmpz_zero, libflint), Nothing,
(Ref{fmpz},), z)
return z
end

function one!(z::fmpz)
ccall((:fmpz_set_ui, libflint), Nothing,
(Ref{fmpz}, UInt),
z, 1)
return z
end

function set!(z::fmpz, a::fmpz)
ccall((:fmpz_set, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}),
z, a)
return z
end

function swap!(a::fmpz, b::fmpz)
ccall((:fmpz_swap, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}),
a, b)
end

function addeq!(z::fmpz, x::fmpz)
ccall((:fmpz_add, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}), z, z, x)
return z
end

function add!(z::fmpz, x::fmpz, y::fmpz)
ccall((:fmpz_add, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}), z, x, y)
return z
end

function add!(z::fmpz, x::fmpz, y::Int)
ccall((:fmpz_add_si, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Int), z, x, y)
return z
end

function add!(z::fmpz, a::fmpz, b::UInt)
ccall((:fmpz_add_ui, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, UInt),
z, a, b)
return z
end

add!(z::fmpz, a::fmpz, b::Integer) = add!(z, a, fmpz(b))
add!(z::fmpz, x::Int, y::fmpz) = add!(z, y, x)

function neg!(z::fmpz, a::fmpz)
ccall((:fmpz_neg, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}),
z, a)
return z
end

function sub!(z::fmpz, a::fmpz, b::fmpz)
ccall((:fmpz_sub, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}),
z, a, b)
return z
end

function sub!(z::fmpz, a::fmpz, b::Int)
ccall((:fmpz_sub_si, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Int),
z, a, b)
return z
end

function sub!(z::fmpz, a::fmpz, b::UInt)
ccall((:fmpz_sub_ui, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, UInt),
z, a, b)
return z
end

function sub!(z::fmpz, a::fmpz, b::Integer)
return sub!(z, a, fmpz(b))
end

function sub!(z::fmpz, b::Integer, a::fmpz)
sub!(z, a, b)
return neg!(z, z)
end


function mul!(z::fmpz, x::fmpz, y::fmpz)
ccall((:fmpz_mul, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}), z, x, y)
Expand All @@ -2006,6 +2098,15 @@ function mul!(z::fmpz, x::fmpz, y::Int)
return z
end

function mul!(z::fmpz, a::fmpz, b::UInt)
ccall((:fmpz_mul_ui, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, UInt),
z, a, b)
return z
end

mul!(z::fmpz, a::fmpz, b::Integer) = mul!(z, a, fmpz(b))

mul!(z::fmpz, x::Int, y::fmpz) = mul!(z, y, x)

function addmul!(z::fmpz, x::fmpz, y::fmpz)
Expand All @@ -2024,29 +2125,24 @@ end

addmul!(z::fmpz, x::fmpz, y::Int, ::fmpz) = addmul!(z, x, y)

function addeq!(z::fmpz, x::fmpz)
ccall((:fmpz_add, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}), z, z, x)
return z
end

function add!(z::fmpz, x::fmpz, y::fmpz)
ccall((:fmpz_add, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}), z, x, y)
function submul!(z::fmpz, a::fmpz, b::fmpz)
ccall((:fmpz_submul, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}),
z, a, b)
return z
end

function add!(z::fmpz, x::fmpz, y::Int)
ccall((:fmpz_add_si, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Int), z, x, y)
function divexact!(z::fmpz, a::fmpz, b::fmpz)
ccall((:fmpz_divexact, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, Ref{fmpz}),
z, a, b)
return z
end

add!(z::fmpz, x::Int, y::fmpz) = add!(z, y, x)

function zero!(z::fmpz)
ccall((:fmpz_zero, libflint), Nothing,
(Ref{fmpz},), z)
function pow!(z::fmpz, a::fmpz, b::Union{Int, UInt})
ccall((:fmpz_pow_ui, libflint), Nothing,
(Ref{fmpz}, Ref{fmpz}, UInt),
z, a, UInt(b))
return z
end

Expand Down
Loading

0 comments on commit cbaba03

Please sign in to comment.