diff --git a/src/implementations/BigInt.jl b/src/implementations/BigInt.jl index 36aa8c45..e196c2ef 100644 --- a/src/implementations/BigInt.jl +++ b/src/implementations/BigInt.jl @@ -25,6 +25,20 @@ promote_operation(::typeof(one), ::Type{BigInt}) = BigInt operate!(::typeof(one), x::BigInt) = Base.GMP.MPZ.set_si!(x, 1) +# abs + +promote_operation(::typeof(abs), ::Type{BigInt}) = BigInt + +function operate!(::typeof(abs), n::BigInt) + n.size = abs(n.size) + return n +end + +function operate_to!(o::BigInt, ::typeof(abs), n::BigInt) + operate_to!(o, copy, n) + return operate!(abs, o) +end + # + promote_operation(::typeof(+), ::Type{BigInt}, ::Type{BigInt}) = BigInt diff --git a/src/implementations/Rational.jl b/src/implementations/Rational.jl index 2c293138..02acd5b0 100644 --- a/src/implementations/Rational.jl +++ b/src/implementations/Rational.jl @@ -51,6 +51,21 @@ end _buffered_simplify(buffer, x::Rational) = _buffered_divgcd(buffer, x.num, x.den) +# abs + +promote_operation(::typeof(abs), ::Type{Q}) where {Q<:Rational} = Q + +function operate!(::typeof(abs), x::Rational) + operate!(abs, x.num) + return x +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 +end + # + and - function promote_operation(