Skip to content
Merged
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
20 changes: 20 additions & 0 deletions src/implementations/BigInt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,26 @@ function operate_to!(
)
end

function buffered_operate_to!(
buffer::BigInt,
output::BigInt,
op::AddSubMul,
x::Scaling,
y::Scaling,
z::Scaling,
args::Vararg{Scaling,N},
) where {N}
return buffered_operate_to!(
buffer,
output,
op,
_scaling_to_bigint(x),
_scaling_to_bigint(y),
_scaling_to_bigint(z),
_scaling_to_bigint.(args)...,
)
end

# Called for instance if `args` is `(v', v)` for a vector `v`.
function operate_to!(
output::BigInt,
Expand Down
36 changes: 36 additions & 0 deletions test/test_big.jl
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,42 @@ function test_alloc()
return
end

function test_buffered_BigInt_mixed_integers()
for op in (MA.add_mul, MA.sub_mul),
args in ((big(2), 3, big(4)), (2, big(3), 4), (big(2), 3, big(4), 5))

expected = op(big.(args)...)
original = deepcopy(args)
output, buffer = big(0), big(0)
@test MA.buffered_operate_to!(buffer, output, op, args...) === output
@test output == expected
@test args == original
end
for op in (MA.add_mul, MA.sub_mul)
expected = op(big(2), big(3), big(4))
output, buffer = big(2), big(4)
@test MA.buffered_operate!(buffer, op, output, 3, buffer) === output
@test output == expected
output = big(0)
@test MA.buffered_operate_to!(output, output, op, big(2), 3, big(4)) ===
output
@test output == expected
end
return
end

function test_Rational_BigInt_mixed_integers()
for op in (+, -), (x, y) in ((big(1) // 2, 1 // 3), (big(7) // 6, 5 // 4))
expected = op(x, y)
@test MA.operate!!(op, deepcopy(x), y) == expected
buffer = MA.buffer_for(op, typeof(x), typeof(y))
output = zero(x)
@test MA.buffered_operate_to!(buffer, output, op, x, y) === output
@test output == expected
end
return
end

end # TestBig

TestBig.runtests()
Loading