Skip to content

Conversation

@tompng
Copy link
Member

@tompng tompng commented Jul 15, 2025

VpDivd was using 1-index in quotient and remainder digits array. c->frac[0] and r->frac[0] was always zero.
Fix to use 0-index. Required MaxPrec of remainder reduces.

Adds a direct test for VpDivd and VpMult.
Added methods BigDecimal#vpdivd BigDecimal#vpmult are enabled only in test build.

Before
XXXX_YYYY_ZZZZ / 0001 = 0000_XXXX_YYYY
00XX_XXYY_YYZZ / 1000 = 0000_0000_0XXX
                        ^^^^
                        unused dead digits

After
XXXX_YYYY_ZZZZ / 0001 = XXXX_YYYY_ZZZZ
00XX_XXYY_YYZZ / 1000 = 0000_0XXX_XYYY

test_vpdivd_with_one and test_vpdivd_intermediate_zero are tests for bug found and fixed in #374

@tompng tompng force-pushed the vpdivd_idnex_fix_with_test branch from c34a916 to b54e1b4 Compare July 15, 2025 18:14
@tompng tompng changed the title Fix VpDivd to fully use remainder array Fix VpDivd to fully use quotient array Jul 15, 2025
@tompng tompng force-pushed the vpdivd_idnex_fix_with_test branch from b54e1b4 to 38e449b Compare July 15, 2025 18:39
VpDivd was using 1-index in quotient and remainder digits array. c->frac[0] and r->frac[0] was always zero.
Fix to use 0-index. Required MaxPrec of remainder reduces.
Add Test for VpDivd expected calculation.
@tompng tompng force-pushed the vpdivd_idnex_fix_with_test branch from 38e449b to b994982 Compare July 15, 2025 18:54
@tompng tompng marked this pull request as ready for review July 15, 2025 18:58
@tompng tompng merged commit 922fa0a into ruby:master Jul 16, 2025
79 checks passed
@tompng tompng deleted the vpdivd_idnex_fix_with_test branch July 16, 2025 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant