Skip to content

Commit

Permalink
feat: readd ad hoc binary operations
Browse files Browse the repository at this point in the history
- We need ZZRingElem * AbstractFloat
- We need QQFieldElem * AbstractFloat
  • Loading branch information
thofma committed Feb 26, 2024
1 parent 4a1abac commit ddd683b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/HeckeMiscInteger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ end
#end


function *(a::ZZRingElem, b::AbstractFloat)
return BigInt(a) * b
end

function *(a::AbstractFloat, b::ZZRingElem)
return a * BigInt(b)
end

function *(a::QQFieldElem, b::AbstractFloat)
return Rational(a) * b
end

function *(a::AbstractFloat, b::QQFieldElem)
return a * Rational(b)
end

function convert(R::Type{Rational{Base.GMP.BigInt}}, a::ZZRingElem)
return R(BigInt(a))
end
Expand Down
11 changes: 11 additions & 0 deletions test/flint/fmpq-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,17 @@ end
@test QQFieldElem(1, 2) // (BigInt(1)//BigInt(2)) == 1

@test QQFieldElem(1, 2) // (1//2) == 1

a = QQ(1//2)
@test a * 1.5 isa BigFloat
@test isapprox(a * 1.5, 0.75)
@test 1.5 * a isa BigFloat
@test isapprox(1.5 * a, 0.75)
@test a * big"1.5" isa BigFloat
@test isapprox(a * big"1.5", big"0.75")
@test big"1.5" * a isa BigFloat
@test isapprox(big"0.75", big"1.5" * a)

end

@testset "QQFieldElem.comparison" begin
Expand Down
10 changes: 10 additions & 0 deletions test/flint/fmpz-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,16 @@ end
@test 5*a == -60

@test a%5 == -2

a = one(ZZ)
@test a * 1.5 isa BigFloat
@test isapprox(a * 1.5, 1.5)
@test 1.5 * a isa BigFloat
@test isapprox(1.5 * a, 1.5)
@test a * big"1.5" isa BigFloat
@test isapprox(a * big"1.5", big"1.5")
@test big"1.5" * a isa BigFloat
@test isapprox(big"1.5" * a, big"1.5")
end

@testset "ZZRingElem.adhoc_division" begin
Expand Down

0 comments on commit ddd683b

Please sign in to comment.