Skip to content

Commit

Permalink
Add sign(::Type{Int}, ::fmpq) (#1366)
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma authored Dec 22, 2022
1 parent 3cee149 commit 5e06a3d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/flint/fmpq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ Return the sign of $a$ ($-1$, $0$ or $1$) as a fraction.
"""
sign(a::fmpq) = fmpq(sign(numerator(a)))

sign(::Type{Int}, a::fmpq) = sign(Int, numerator(a))

function abs(a::fmpq)
z = fmpq()
ccall((:fmpq_abs, libflint), Nothing, (Ref{fmpq}, Ref{fmpq}), z, a)
Expand Down
3 changes: 3 additions & 0 deletions test/flint/fmpq-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ end
@test sign(fmpq(-2, 3)) == -1
@test sign(fmpq()) == 0
@test sign(fmpq(1, 7)) == 1
@test sign(Int, fmpq(-2, 3)) == -1
@test sign(Int, fmpq()) == 0
@test sign(Int, fmpq(1, 7)) == 1

@test isone(one(R))

Expand Down

0 comments on commit 5e06a3d

Please sign in to comment.