20 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto e60acfc6ff mruby-numeric-ext: add Integer#bit_length
Implement Integer#bit_length in mrbgems/mruby-numeric-ext.
- Fixnum: zero returns 0; negatives follow ~self rule; count bits by shifts.
- Bigint (MRB_USE_BIGINT): handle sign; negatives via mrb_bint_rev, then bit
  length via length of mrb_bint_to_s(..., 2).
- Add tests in mrbgems/mruby-numeric-ext/test/numeric.rb.
- Update README with examples.

Co-authored-by: Codex CLI <codex@openai.com>
2025-08-14 10:53:12 +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 e42523fcf4 mruby-numeric-ext: add test for Integer.sqrt() 2025-04-16 23:30:23 +09:00
Yukihiro "Matz" Matsumoto 79dda053a5 mruby-numeric-ext: add test for Integer#digits 2024-11-23 23:16:47 +09:00
Hoshiumi Arata 612941dcbc Add test code for even?/odd? 2024-07-23 21:09:17 +09:00
Yukihiro "Matz" Matsumoto f05574606e mruby-numeric-ext: add ceildiv test with Float and Rational. 2022-09-12 10:27:29 +09:00
Yukihiro "Matz" Matsumoto b6d7564846 numeric_ext.rb: add Integer#ceildiv. 2022-09-12 10:27:28 +09:00
Yukihiro "Matz" Matsumoto 4dcdf78f8a numeric_ext.c: add Integer#pow() method.
Which takes optional second argument of modulo.
2022-03-17 23:25:50 +09:00
KOBAYASHI Shuji c980fe2792 Integrate Integral#chr (Fixnum#chr) to mruby-string-ext
Because they're defined in both `mruby-string-ext` and `mruby-numeric-ext`
(they seem more natural to define in N, but `mruby-string-ext` depends on
`Integral#chr`).
2019-07-21 22:59:41 +09:00
Yukihiro "Matz" Matsumoto cca19532c5 Remove Kernel#class_defined? which is not available in CRuby; #3829 2019-01-03 11:34:35 +09:00
YAMAMOTO Masaya b0cdb93a3a Support MRB_WIHTOUT_FLOAT to mruby-numeric-ext (test only) 2017-10-16 18:14:34 +09:00
takahashim 40a9700ef8 support Numeric#zero? and Numeric#nonzero? 2015-11-20 23:39:45 +09:00
take_cheeze 4a6c651f82 Run mrbgem and core tests on minimum dependencies.
Solves #2355.

In test drivers:
* Uses `mrb_t_pass_result` to check and pass test result to main `mrb_state`.
* Adds `mrb_init_test_driver` to init test `mrb_state`.
2014-07-12 20:36:45 +09:00
Tomoyuki Sahara 4ad0896bda add Integer#div and Float#div. 2014-03-04 12:45:11 +09:00
chasonr d60944ef3a Test for UTF-8 as mattn suggests.
The string is "Hello world" in Japanese.  (hat tip:  Google Translate.)
2014-02-27 23:42:07 -05:00
chasonr b752b01a56 Update the Fixnum#chr test for UTF-8. 2014-02-26 20:53:23 -05:00
Daniel Bovensiepen 9a7efd69ee Improve test of mruby-numeric-ext GEM 2013-08-04 22:41:26 +08:00
Kouki Ooyatsu d3ff90f5fc fix comment 2013-03-08 10:42:28 +09:00
Kouki Ooyatsu 6dfc276230 add Integer#chr test case: multibyte (raise RangeError) 2013-03-08 10:42:18 +09:00
Kouki Ooyatsu 6c066302e2 add mrbgems/ext/mruby-numeric, and method: Integer#chr 2013-03-08 10:05:41 +09:00