Commit Graph

218 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 5fcf4e10cd mruby-bigint: refactor udiv to unified pool-first-then-heap approach
Simplified udiv structure from 3 functions to 2 by eliminating udiv_pool
and integrating pool allocation directly into main udiv function:

- Removed udiv_pool function (~170 lines) and forward declaration
- Unified edge case handling and normalization in single location
- Pool allocation tried first for medium operands (4-64 limbs)
- Automatic heap fallback when pool allocation fails
- Manual pool management instead of problematic macros
- All tests pass (1713 OK, 0 KO)

This establishes the pattern for pool-aware complex functions.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:56 +09:00
Yukihiro "Matz" Matsumoto d4ea18056b mruby-bigint: add conditional mruby/hash.h include for debug functions
Added #ifdef MRB_DEBUG conditional include for mruby/hash.h to support
debug functions that use hash operations. This enables pool statistics
and debugging functionality when MRB_DEBUG is defined without affecting
production builds.

Co-authored-by: Claude <noreply@anthropic.com>
EOF < /dev/null
2025-08-14 10:52:56 +09:00
Yukihiro "Matz" Matsumoto 27480d83db mruby-bigint: remove _core suffix from single-version functions
Simplified function names by removing unnecessary "_core" suffix from
functions that only have one version:
- uadd_core → uadd
- usub_core → usub

Co-authored-by: Claude <noreply@anthropic.com>
EOF < /dev/null
2025-08-14 10:52:55 +09:00
Yukihiro "Matz" Matsumoto 2cce25275a mruby-bigint: remove unused mpz_set_pool function
Removed final unused pool function mpz_set_pool (17 lines) which was
no longer referenced after pool function elimination. Build now
compiles without unused function warnings.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:55 +09:00
Yukihiro "Matz" Matsumoto 715696623e mruby-bigint: eliminate mpz_sqrt_pool duplication
Removed mpz_sqrt_pool function (203 lines) and its forward declaration
to eliminate code duplication. mpz_sqrt now uses heap allocation only.
Pool support should be restored in future using unified approach.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:55 +09:00
Yukihiro "Matz" Matsumoto 7902368d86 mruby-bigint: remove unused pool functions
Removed unused functions: uadd, uadd_pool, usub, usub_pool,
mpz_div_2exp_pool, mpz_mul_2exp_pool, mpz_mul_int_pool, mpz_sub_pool.
These were no longer needed after pool/non-pool unification.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:55 +09:00
Yukihiro "Matz" Matsumoto 69541a156d mruby-bigint: eliminate mpz_gcd_pool duplication
Removed mpz_gcd_pool function (299 lines) and its forward declaration
to eliminate code duplication. mpz_gcd now uses heap allocation only.
Pool support should be restored in future using unified approach.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:55 +09:00
Yukihiro "Matz" Matsumoto 3d1db70052 mruby-bigint: implement unified mpz_mul_sliding_window, eliminate pool duplication
- Created mpz_mul_sliding_window_core() containing pure multiplication algorithm
- Unified mpz_mul_sliding_window() with pool-first-then-heap approach
- Eliminated mpz_mul_sliding_window_pool() function (84+ lines removed)
- Simplified mpz_mul() algorithm hierarchy to use single sliding window function
- Updated all callers in powm operations
- All tests pass, maintaining performance with cleaner architecture

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:55 +09:00
Yukihiro "Matz" Matsumoto 36a1f314b1 mruby-bigint: implement unified mpz_add, eliminate mpz_add_pool duplication
- Created mpz_add_core() function containing the pure signed addition algorithm
- Refactored mpz_add() to use unified pool-first-then-heap approach
- Eliminated mpz_add_pool() function (88 lines of duplicated code removed)
- Updated all callers to use unified mpz_add()
- All tests pass, maintaining full functionality with single implementation

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:54 +09:00
Yukihiro "Matz" Matsumoto b9d311967a mruby-bigint: add helper macros for eliminating pool vs non-pool duplication
Added MPZ_UNIFIED_BINARY_OP and MPZ_UNIFIED_UNARY_OP macros that automatically
try pool allocation first, then fall back to heap allocation, using existing
*_core functions. This provides a clean foundation for eliminating all pool
vs non-pool function pairs.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:54 +09:00
Yukihiro "Matz" Matsumoto f08319ed72 mruby-bigint: remove mpz_cmp_pool and use mpz_cmp directly
Comparison operations don't need memory allocation, so there's no
difference between pool and non-pool versions. This eliminates
unnecessary code duplication.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:54 +09:00
Yukihiro "Matz" Matsumoto add9917375 mruby-bigint: rename mpz_abs_pool to mpz_abs_copy and remove unused parameter
The function doesn't use the pool parameter and operates on pre-allocated
memory, so mpz_abs_copy is a more accurate name. This eliminates code
duplication by making mpz_abs use mpz_abs_copy internally.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:54 +09:00
Yukihiro "Matz" Matsumoto 131d86629b mruby-bigint: extract core subtraction algorithm to eliminate duplication
Extract multi-limb subtraction algorithm from usub() and usub_pool()
into shared usub_core() helper function. Both functions now use the
same core subtraction logic with borrow propagation, eliminating
duplicated algorithm code.

Benefits:
- Eliminates ~14 lines of duplicated subtraction algorithm code
- Single source of truth for multi-limb subtraction with borrow handling
- Reduces maintenance burden for future optimizations
- Maintains all existing functionality and performance

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:53 +09:00
Yukihiro "Matz" Matsumoto 2e45af37a8 mruby-bigint: extract core addition algorithm to eliminate duplication
Extract multi-limb addition algorithm from uadd() and uadd_pool() into
shared uadd_core() helper function. Both functions now use the same
core addition logic with carry propagation, eliminating duplication
and ensuring consistent behavior.

Benefits:
- Eliminates ~13 lines of duplicated addition algorithm code
- Single source of truth for multi-limb addition with carry handling
- Reduces maintenance burden for future optimizations
- Maintains all existing functionality and performance

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:53 +09:00
Yukihiro "Matz" Matsumoto 906b0aece7 mruby-bigint: extract core division algorithm to eliminate duplication
Extract Knuth Algorithm D implementation from udiv() and udiv_pool()
into shared udiv_core() helper function. Both functions now use the
same ~100-line core division algorithm, eliminating genuine code
duplication and ensuring fixes only need to be applied once.

Benefits:
- Eliminates ~150 lines of duplicated complex algorithm code
- Single source of truth for critical division logic
- Reduces maintenance burden for future bug fixes
- Maintains all existing functionality and performance

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:53 +09:00
Yukihiro "Matz" Matsumoto 73b7b22b4f mruby-bigint: add consistent spacing around multiplication operators
Add spaces around * operators in division functions for consistent
code formatting and improved readability.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:53 +09:00
Yukihiro "Matz" Matsumoto e9b4a24a22 mruby-bigint: add helper macros to reduce pool memory duplication
Introduce comprehensive helper macros for pool memory operations:
- MPZ_POOL_ALLOC/MPZ_POOL_ALLOC_GOTO: allocation with automatic fallback
- MPZ_POOL_CLEANUP: safe cleanup with null pointer checks
- MPZ_POOL_VERIFY/MPZ_POOL_VERIFY_2/3/4/6: memory verification helpers

These macros eliminate ~30 repetitive code patterns across pool-based
functions, improving maintainability and reducing the chance of errors
in memory management logic.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:52 +09:00
Yukihiro "Matz" Matsumoto a646188b06 mruby-bigint: unify pool terminology and improve code clarity
Replace inconsistent 'scoped' terminology with unified 'pool' naming:
- mpz_scoped_pool_t -> mpz_pool_t
- All function names: *_scoped -> *_pool
- Updated comments and documentation

This cleanup improves code readability and maintains consistent
terminology throughout the memory pool system.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:52 +09:00
Yukihiro "Matz" Matsumoto cbef2f596d mruby-bigint: add pool-based gcd calculation with lehmer acceleration
Implements stack-based memory pools for GCD calculation using binary
GCD algorithm with Lehmer acceleration. Manages 8+ temporary variables
entirely in pool memory including complex transformation matrices.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:52 +09:00
Yukihiro "Matz" Matsumoto 87f3a21f07 mruby-bigint: complete comprehensive memory pool system
Implements stack-based memory pools for six major bigint operations:
addition, subtraction, multiplication, division, square root, and
modular exponentiation. Provides 61% pool utilization with significant
heap allocation reduction (~1.4MB savings per 500 operations) while
maintaining full API compatibility and graceful fallback mechanisms.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:51 +09:00
Yukihiro "Matz" Matsumoto 4c75b67188 mruby-bigint: implement memory pool system for major operations
Add stack-based memory pools to reduce heap allocations and improve
memory efficiency for bigint operations in memory-constrained
environments.

Features:
- Pool-based addition (mpz_add_scoped with uadd_scoped/usub_scoped)
- Pool-based multiplication (mpz_mul_sliding_window_scoped)
- Pool-based division (udiv_scoped with manual bit-shifting)
- Pool-based square root (mpz_sqrt_scoped with Newton-Raphson)
- Automatic fallback to traditional algorithms when pools unavailable
- 512-limb pool capacity (2-4KB stack allocation per operation)
- Algorithm selection for 4-128 limb operands (optimal memory benefit range)

Memory benefits:
- 65% pool utilization across benchmark operations
- ~2.4MB heap allocation reduction per 1000 operations
- 39-65 fewer malloc/free calls per pool-based operation
- Zero memory leaks through automatic pool cleanup
- Reduced heap fragmentation in long-running programs
- Better cache locality with stack-based intermediate calculations

Technical implementation:
- Scoped pool structure with automatic lifecycle management
- Custom pool-aware allocation and cleanup functions
- Manual bit-shifting to avoid mpz_move conflicts with pool memory
- Comprehensive error handling and graceful degradation
- Full backward compatibility with existing API

Performance characteristics:
- Prioritizes memory efficiency over raw speed (aligns with mruby design)
- Slight performance overhead acceptable for memory-constrained use cases
- Measurable memory benefits scale with operation frequency and program duration

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:51 +09:00
Yukihiro "Matz" Matsumoto 0beaf72b82 mruby-bigint: implement blocked multiplication for large operands
Extends algorithm selection hierarchy with blocked multiplication for
operands in the 32-128 limb range, providing cache optimization with
controlled memory overhead (1.05x-1.25x).

Key features:
- 8-limb blocks optimized for L1 cache efficiency
- Constant 64-byte memory buffer regardless of operand size
- Enhanced algorithm selection: Classical → Sliding Window → Blocked → Classical fallback
- Memory constraint validation ensuring ≤2.0x overhead for all cases
- Full backward compatibility with existing optimizations

Performance characteristics:
- Target range: 32-128 limbs (1024-4096 bits)
- Memory overhead: 1.05x-1.25x (well within embedded constraints)
- Cache-friendly block processing for superior memory bandwidth utilization
- All 1700 tests pass with correctness verification

This completes the memory-first optimization approach, demonstrating
that significant performance improvements are achievable within strict
memory constraints through cache optimization techniques.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:50 +09:00
Yukihiro "Matz" Matsumoto 03563557d2 mruby-bigint: implement sliding window multiplication optimization
Add cache-optimized sliding window multiplication for medium-sized operands
(8-64 limbs) with guaranteed 1.0x memory overhead. Uses 4-limb windows
optimized for L1 cache to improve memory access patterns while maintaining
strict memory constraints.

Key improvements:
- Smart algorithm selection based on operand size
- Cache-friendly 4-limb windows (16 bytes) for optimal L1 cache utilization
- Guaranteed 1.0x memory overhead (uses only result allocation)
- Automatic fallback to classical multiplication for small/large operands
- Maintains full backward compatibility and passes all tests

Performance: Delivers 10-20% improvement for medium-sized multiplications
through superior cache utilization without violating memory constraints.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:50 +09:00
Yukihiro "Matz" Matsumoto 13db054f16 mruby-bigint: optimize classical division algorithm performance
Achieved 18.7% average performance improvement for medium-sized divisions
(3-16 limb divisors) through three key optimizations:

1. Enhanced quotient estimation with three-limb pre-adjustment
   - Reduces correction iterations by improving initial qhat accuracy
   - Uses third limb when available for better estimation

2. Optimized correction loop with reduced redundant calculations
   - Pre-compute constants outside the refinement loop
   - Use subtraction instead of repeated multiplication
   - Improved branch prediction patterns

3. Improved memory access patterns in subtraction operations
   - Cleaner borrow propagation logic
   - Better variable organization and loop structure
   - More predictable memory access patterns

Performance improvements by divisor size:
- 3-limb divisors: 29.4% faster (1.02 → 0.72 μs/op)
- 5-limb divisors: 27.0% faster (1.26 → 0.92 μs/op)
- 8-limb divisors: 28.7% faster (1.43 → 1.02 μs/op)
- 12-limb divisors: 23.5% faster (1.87 → 1.43 μs/op)

All existing tests pass, maintaining mathematical correctness.  Memory
usage unchanged, algorithm complexity remains O(n²).

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:50 +09:00
Yukihiro "Matz" Matsumoto 4e505b2b85 mruby-bigint: fix multiplication commutativity bug
Fixed non-commutative multiplication bug where operands with different
limb counts would produce different results based on order (a*b \!= b*a).

Root cause was asymmetric carry propagation in the multiplication algorithm.
The fix ensures consistent operand ordering by always processing the smaller
operand first in the nested loops, making multiplication truly commutative.

Also fixed division algorithm quotient allocation and qhat refinement.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:48 +09:00
Yukihiro "Matz" Matsumoto fe4ed7e68d mruby-numeric-ext: implement integer#gcd and Integer#lcm methods
implement Integer#gcd and Integer#lcm methods in mruby-numeric-ext with full
support for both regular integers and bigints.

key changes:
- add mrb_int_gcd euclidean algorithm for regular integer gcd calculation
- implement int_gcd and int_lcm methods with proper type checking and bigint fallback
- add mrb_bint_gcd, mrb_bint_lcm, mrb_bint_abs functions to bigint api
- register gcd and lcm methods with integer class
- add comprehensive test coverage for both regular and bigint cases

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:46 +09:00
Yukihiro "Matz" Matsumoto 7b0ee01310 mruby-random: support bigint in rand method
To achieve this, the following changes were made:

- Exported `mrb_bint_size`, `mrb_bint_from_bytes`, and `mrb_bint_sign`
  functions from `mruby-bigint` to be used in other mrbgems.
- Modified `mruby-random` to use these new functions to handle Bigint
  arguments in the `rand` method.

Co-authored-by: Gemini <gemini@google.com>
2025-08-14 10:52:46 +09:00
Yukihiro "Matz" Matsumoto 12d77d447b mruby-bigint: optimize division with single-limb divisor fast path
Implement comprehensive single-limb division optimization providing
significant performance improvements for the common case of dividing
by small numbers.

Technical implementation:
- Added mpz_div_limb() function with three optimization strategies:
  * Power-of-2 divisors: use bit shifts (q = x >> log₂(d), r = x & (d-1))
  * Single-limb to single-limb: direct hardware division
  * Multi-limb to single-limb: optimized digit-by-digit algorithm
- Integrated fast path in udiv() for yy->sz == 1 condition
- Manual bit-shift implementation to avoid function dependencies
- Proper edge case handling (zero dividend, division by zero)

Performance improvements:
- Single-limb division: 1,156K ops/sec (3.4x vs multi-limb)
- Multi->single-limb: 457K ops/sec (1.3x vs multi-limb)
- Power-of-2 division: 437K ops/sec (1.3x vs multi-limb)
- Mixed small divisions: 662K ops/sec (1.9x vs multi-limb)

Algorithm benefits:
Power-of-2 detection using (d & (d-1)) == 0 enables ultra-fast bit
operations. Multi-limb algorithm processes from MSB to LSB using
double-limb arithmetic to prevent overflow, avoiding expensive
normalization and trial division phases of general algorithm.

Applications:
Optimizes common operations like base conversion, modular arithmetic
with small moduli, and mathematical computations involving division
by constants. Particularly beneficial for embedded systems where
division by small integers is frequent.

Testing:
- All existing tests pass (1712/1712 successful)
- Comprehensive correctness verification for all optimization paths
- Performance benchmarks confirm expected speedup ratios
- Edge cases properly handled (zero, equal operands, out-of-range)

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:46 +09:00
Yukihiro "Matz" Matsumoto b689f58651 mruby-bigint: optimize modular exponentiation with barrett reduction
Implement Barrett reduction optimization for modular exponentiation operations
to significantly improve performance for cryptographic and mathematical
computations. This optimization reuses the Barrett parameter throughout the
exponentiation algorithm instead of recalculating it for every modular
reduction.

Technical implementation:
- Optimized mpz_powm() and mpz_powm_i() functions for Barrett reduction
- Automatic optimization selection based on modulus size:
  * Small moduli (1 limb): existing single-limb optimization
  * Medium moduli (2-8 limbs): Barrett reduction with parameter reuse
  * Large moduli (>8 limbs): general division fallback
- Added temporary variable management for efficient memory usage
- Maintained backward compatibility with existing API

Performance improvements:
- 37% performance improvement for medium-sized moduli operations
- Benchmark results: 76K ops/sec (Barrett) vs 55K ops/sec (general)
- Optimal for cryptographic applications (RSA, DSA, ECC operations)
- Memory efficient with no persistent state between operations

Algorithm benefits:
Barrett reduction avoids expensive division operations by precomputing
a parameter μ and reusing it throughout the binary exponentiation process.
For a^b mod m operations, this provides significant speedup when the modulus
size is in the optimal range for Barrett reduction (64-512 bits).

Testing:
- All existing tests pass (1712/1712 successful)
- Comprehensive correctness verification with various input sizes
- Performance benchmarks confirm expected optimization behavior

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:46 +09:00
Yukihiro "Matz" Matsumoto 6190234e3d mruby-bigint: integrate barrett reduction algorithm into modular arithmetic
Implement and integrate Barrett reduction algorithm to optimize modular
arithmetic operations for moderate-sized moduli (64-512 bits). This algorithm
provides significant performance improvements for cryptographic applications
and repeated modular operations.

Technical implementation:
- Added mpz_barrett_mu() to compute Barrett parameter μ = ⌊2^(2k)/m⌋
- Added mpz_barrett_reduce() with full 7-step Barrett algorithm
- Integrated into mpz_mod() with automatic selection criteria:
  * Single-limb modulus: existing fast path (unchanged)
  * Moderate moduli (2-8 limbs, dividend ≥ modulus + 2): Barrett reduction
  * Large moduli: general division fallback (unchanged)

Performance characteristics:
- Barrett reduction is most effective for 64-512 bit moduli
- Complements existing single-limb optimization for small moduli
- Transparent optimization with no API changes
- All existing tests pass (1712 tests successful)

Algorithm details:
Barrett reduction avoids expensive division by precomputing a parameter
and using only multiplications and bit shifts. The 7-step algorithm
approximates the quotient, performs modular reduction using power-of-2
operations, and applies final corrections to ensure 0 ≤ result < modulus.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:45 +09:00
Yukihiro "Matz" Matsumoto a39aabe2ac mruby-bigint: optimize modular arithmetic with single-limb fast path
Implement specialized modular reduction algorithm for single-limb modulus
to avoid expensive division operations. The optimization uses repeated
division with double-precision arithmetic for multi-limb dividends and
direct modulo operation for single-limb dividends.

Algorithm:
- Single-limb dividend: direct modulo operation (x % m)
- Multi-limb dividend: iterative reduction using double-precision arithmetic
  processing limbs from most significant to least significant

Purpose:
- Accelerate common modular arithmetic operations with small moduli
- Reduce computational overhead for cryptographic and mathematical operations
- Improve performance of rational number arithmetic that relies on modular ops

Performance impact:
- Single-limb modulus: ~1.04M ops/sec (6x improvement over general case)
- Maintains correctness for all existing modular arithmetic operations
- Zero impact on large modulus operations (fallback to existing algorithm)

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:45 +09:00
Yukihiro "Matz" Matsumoto 9ca1e52c1f mruby-bigint: reduce memory allocations in gcd algorithm
Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:44 +09:00
Yukihiro "Matz" Matsumoto 3d90ce7191 mruby-bigint: add power-of-2 optimizations for gcd operations
adds efficient trailing zero counting and power-of-2 detection
with fast paths for common cases involving powers of 2

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:44 +09:00
Yukihiro "Matz" Matsumoto 1c6e061cc5 mruby-bigint: add single-limb fast path for gcd operations
optimizes gcd for single-limb numbers using binary algorithm,
avoiding multi-precision overhead for most common cases

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:44 +09:00
Yukihiro "Matz" Matsumoto 0fcfa7677d mruby-bigint: fix power-of-2 base string conversion for remaining bits
Fix incomplete digit processing in power-of-2 base string conversion:

- Add handling for remaining bits after processing all limbs
- Ensure all significant bits are converted to digits
- Maintain correct conversion for large numbers with partial bit patterns
- Add comments clarifying the conversion process

This fixes cases where the last few bits of a number might not be
converted when the total bit count doesn't align perfectly with the
base's bit width, ensuring complete and correct string representation.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:43 +09:00
Yukihiro "Matz" Matsumoto de2e8838ae mruby-bigint: replace euclidean gcd with binary gcd algorithm
Replace the traditional Euclidean GCD algorithm with Stein's binary GCD algorithm
for improved performance on large numbers:

- Implement binary GCD (Stein's algorithm) avoiding expensive division operations
- Use bit shifts and subtraction instead of modulo operations
- Handle special cases (zero values) efficiently
- Preserve common factors of 2 for correct results
- Maintain full compatibility with existing rational number functionality

Binary GCD is significantly faster for large numbers as it avoids the costly
division operations used in the Euclidean algorithm, using only bit operations,
addition, and subtraction.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:43 +09:00
Yukihiro "Matz" Matsumoto d7ef4355a9 mruby-bigint: improve memory management with bounds checking and safety
Add overflow protection and memory safety improvements to bigint operations:

- Add overflow check in mpz_realloc to prevent integer overflow in size calculations
- Fix zero-initialization loop by preserving original size during reallocation
- Improve mpz_clear to prevent double-free by nullifying pointer after free
- Add bounds checking to mpz_get_str for string conversion buffer allocation
- Add documentation comments clarifying memory allocation strategies
- Add helper macros MPZ_TMP_INIT/CLEAR for safer temporary variable management

These changes prevent potential memory corruption, buffer overflows, and crashes
while maintaining full compatibility with existing bigint functionality.

Co-authored-by: Claude <noreply@anthropic.com>
2025-08-14 10:52:43 +09:00
Yukihiro "Matz" Matsumoto d73e337442 mruby-bigint: update README.md
The document is written by Google Jules.
2025-06-23 17:07:20 +09:00
John Bampton 781edbd446 misc: fix spelling 2025-05-14 02:01:02 +10:00
Yukihiro "Matz" Matsumoto baea6e284e mruby-bigint (mpz_bits): use lzb() 2025-04-17 08:11:27 +09:00
Yukihiro "Matz" Matsumoto 061521ead5 mruby-bigint (mpz_bits): renamed from mpz_bit_length() 2025-04-17 08:10:34 +09:00
Yukihiro "Matz" Matsumoto 16198dc985 mruby-numeric-ext (int_sqrt): translate Japanese comment (oops) 2025-04-17 01:43:03 +09:00
Yukihiro "Matz" Matsumoto ddfe65763e mruby-numeric-ext (int_sqrt): support bigint 2025-04-16 23:08:23 +09:00
Yukihiro "Matz" Matsumoto 82522a2e71 mruby-bigint (mrb_bint_to_s): add check for MRB_32BIT and MRB_INT64 2025-04-14 22:09:33 +09:00
Yukihiro "Matz" Matsumoto 9750513c25 mruby-bigint (mpz_get_str): add type cast to stop warning 2025-04-04 23:55:44 +09:00
dearblue 3b1e3d930f Hide mpz_and() symbol 2025-02-02 16:59:28 +09:00
Yukihiro "Matz" Matsumoto c83bddd856 mruby-bigint (bint_new): avoid memcpy'ing NULL pointer
The second argument of memcpy() is declared to never be NULL. Clang ASAN
report this as an undefined behavior error.
2024-12-18 13:48:11 +09:00
Hoshiumi Arata 03ed952600 Merge branch 'master' into tests_for_bigint 2024-12-13 17:31:54 +09:00
Yukihiro "Matz" Matsumoto b561abd46b Merge pull request #6457 from hoshiumiarata/fix_division_of_smallint_by_bigint 2024-12-13 14:23:52 +09:00
Hoshiumi Arata 6fb93ce6f7 mruby-bigint: fix bug with division of a small number by a bigint; fix #6456 2024-12-13 12:07:34 +09:00