From c38e321192779fa7fdfeb290e4c08460d1595cdc Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Sun, 13 Sep 2026 09:21:41 -0400 Subject: [PATCH] Support mixed scalar inputs in buffered BigInt arithmetic Convert Scaling inputs for buffered add/sub-multiply as in the unbuffered implementation, fixing mixed rational subtraction and preserving aliases. Co-Authored-By: Chris Rackauckas Co-Authored-By: Codex Agent-Harness: Codex CLI 0.154.0 Agent-Model: gpt-6-astra Agent-Session: local session ID 01a099aa-308a-7fd3-91bd-9fb2dc357b91 --- src/implementations/BigInt.jl | 20 +++++++++++++++++++ test/test_big.jl | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/implementations/BigInt.jl b/src/implementations/BigInt.jl index 4bf0966..f8bd865 100644 --- a/src/implementations/BigInt.jl +++ b/src/implementations/BigInt.jl @@ -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, diff --git a/test/test_big.jl b/test/test_big.jl index 96d28a0..9cd8672 100644 --- a/test/test_big.jl +++ b/test/test_big.jl @@ -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()