mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
9e6f2809ce
Replace the repeated-division approach with Knuth's base conversion algorithm for decimal string conversion. This processes each input limb once (MSB to LSB) and builds the decimal representation incrementally, which is faster than dividing the entire number repeatedly. Performance improvement for to_s on numbers under D&C threshold: - 128 bits: 2.5x faster (0.80 -> 0.32 us) - 256 bits: 3.6x faster (1.47 -> 0.41 us) - 512 bits: 5.0x faster (3.47 -> 0.69 us) - 1024 bits: 6.1x faster (9.37 -> 1.55 us) - 2048 bits: 6.4x faster (31.0 -> 4.82 us) Also includes: - Montgomery reduction for modular exponentiation (powm) - Adjusted Barrett reduction threshold to >= 4 limbs Co-authored-by: Claude <noreply@anthropic.com>