Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement abs for BigInt and Rational #244

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/implementations/BigInt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@

operate!(::typeof(one), x::BigInt) = Base.GMP.MPZ.set_si!(x, 1)

# abs

promote_operation(::typeof(abs), ::Type{BigInt}) = BigInt

Check warning on line 30 in src/implementations/BigInt.jl

View check run for this annotation

Codecov / codecov/patch

src/implementations/BigInt.jl#L30

Added line #L30 was not covered by tests

function operate!(::typeof(abs), n::BigInt)
n.size = abs(n.size)
return n

Check warning on line 34 in src/implementations/BigInt.jl

View check run for this annotation

Codecov / codecov/patch

src/implementations/BigInt.jl#L32-L34

Added lines #L32 - L34 were not covered by tests
end

function operate_to!(o::BigInt, ::typeof(abs), n::BigInt)
operate_to!(o, copy, n)
return operate!(abs, o)

Check warning on line 39 in src/implementations/BigInt.jl

View check run for this annotation

Codecov / codecov/patch

src/implementations/BigInt.jl#L37-L39

Added lines #L37 - L39 were not covered by tests
end

# +

promote_operation(::typeof(+), ::Type{BigInt}, ::Type{BigInt}) = BigInt
Expand Down
15 changes: 15 additions & 0 deletions src/implementations/Rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@

_buffered_simplify(buffer, x::Rational) = _buffered_divgcd(buffer, x.num, x.den)

# abs

promote_operation(::typeof(abs), ::Type{Q}) where {Q<:Rational} = Q

Check warning on line 56 in src/implementations/Rational.jl

View check run for this annotation

Codecov / codecov/patch

src/implementations/Rational.jl#L56

Added line #L56 was not covered by tests

function operate!(::typeof(abs), x::Rational)
operate!(abs, x.num)
return x

Check warning on line 60 in src/implementations/Rational.jl

View check run for this annotation

Codecov / codecov/patch

src/implementations/Rational.jl#L58-L60

Added lines #L58 - L60 were not covered by tests
end

function operate_to!(o::Q, ::typeof(abs), x::Q) where {Q<:Rational}
operate_to!(o.num, abs, x.num)
operate_to!(o.den, copy, x.den)
return o

Check warning on line 66 in src/implementations/Rational.jl

View check run for this annotation

Codecov / codecov/patch

src/implementations/Rational.jl#L63-L66

Added lines #L63 - L66 were not covered by tests
end

# + and -

function promote_operation(
Expand Down