Yukihiro "Matz" Matsumoto
32aed6ad8c
mruby-bigint: increase KARATSUBA_THREASHOLD to 512
...
Since Karatsuba algorithm is far heavier than the basic multiplication,
we have increased KARATSUBA_THREASHOLD and decreased MAX_RECURSION_DEPTH.
2024-10-04 18:10:14 +09:00
Yukihiro "Matz" Matsumoto
6820da1526
mruby-bigint (mpz_abs): use zero_p()
2024-10-04 18:10:14 +09:00
Yukihiro "Matz" Matsumoto
fd8d3a8d70
mruby-bigint: use zero() to make mpz_t zero.
2024-10-04 18:10:14 +09:00
Yukihiro "Matz" Matsumoto
6274f8de43
mruby-bigint (mpz_sub): avoid data copy
...
Since mpz_sub() calls mpz_add() with opposite sign, refer same data from
the original, instead of copying whole data.
2024-10-04 18:10:14 +09:00
Yukihiro "Matz" Matsumoto
363754b5d1
mruby-bigint (uzero_p): check from the top, not bottom
...
For most of the case, the first non-zero value would be found earlier
when search starts from the top.
2024-10-04 18:10:14 +09:00
Yukihiro "Matz" Matsumoto
fcc1832efc
mruby-bigint (mul_karatsuba): avoid copying operand u and v
2024-09-30 18:32:26 +09:00
Yukihiro "Matz" Matsumoto
0023cbdb3d
mruby-bigint (mpz_mul): use Karatsuba algorithm to improve performance
2024-09-28 05:26:40 +09:00
Yukihiro "Matz" Matsumoto
f6caf0d788
mruby-bigint (mrb_init_set_str): reduce mpz_t allocations
2024-09-19 20:52:11 +09:00
Yukihiro "Matz" Matsumoto
bdbf8536a7
mruby-bigint: rename add_d and sub_d to add_n and sub_n respectively
...
`_n` suffix represents `no_normalize`.
2024-09-15 03:02:41 +09:00
Yukihiro "Matz" Matsumoto
44908e5cba
mruby-rational: support bigint numerators & denominators
2024-08-16 15:12:03 +09:00
Yukihiro "Matz" Matsumoto
92f476d8fa
mruby-bigint (mpz_set): trim destination mpz_t
2024-08-16 07:32:05 +09:00
Yukihiro "Matz" Matsumoto
e9c4486e27
mruby-bigint: add fast path to mrb_bint_mul() & mrb_bint_div()
2024-08-14 22:36:47 +09:00
Yukihiro "Matz" Matsumoto
6e5a493ff3
mruby-bigint (mrb_bint_new_float): add fast path for FIXABLE_FLOAT
2024-08-14 16:11:27 +09:00
Yukihiro "Matz" Matsumoto
6da2e60edc
mruby-bigint (mpz_get_str): avoid malloc when base is a power of 2
2024-08-05 10:43:47 +09:00
Yukihiro "Matz" Matsumoto
ab95e042ca
mruby-bigint (mrb_bint_xor): add fast path with fixnums
2024-07-29 16:44:54 +09:00
Yukihiro "Matz" Matsumoto
b706c89c41
mruby-bigint (mrb_bint_2comp): fix assertion
2024-07-29 16:44:54 +09:00
Yukihiro "Matz" Matsumoto
bf7f14341d
mruby-bigint (mrb_bint_or): add fast path with fixnums
2024-07-29 15:47:19 +09:00
Yukihiro "Matz" Matsumoto
dcf7adeeb7
mruby-bigint: use zero_p()
2024-07-29 15:43:22 +09:00
Yukihiro "Matz" Matsumoto
196c2bd0b9
mruby-bigint (mrb_bint_add): add type cast to stop warnings in C++
2024-07-28 23:29:54 +09:00
Yukihiro "Matz" Matsumoto
081cd0627f
mruby-bigint (mrb_bint_hash): need to get hash from all digits
2024-07-27 18:54:50 +09:00
Yukihiro "Matz" Matsumoto
203a89a3f2
mruby-bigint (zero_p): define a new predicate to check if mpz_t is 0
2024-07-27 18:54:50 +09:00
Yukihiro "Matz" Matsumoto
234a2b10fb
mruby-bigint (mpz_neg): no need to check x != y
2024-07-27 18:54:50 +09:00
Yukihiro "Matz" Matsumoto
811637e99f
mruby-bigint (mrb_bint_2comp): inline mpz_2comp
2024-07-27 18:54:49 +09:00
Yukihiro "Matz" Matsumoto
c218894af9
mruby-bigint: use mp_limb instead of uint32_t
...
Because mp_limb may be uint16_t on some platforms.
2024-07-27 18:54:48 +09:00
Yukihiro "Matz" Matsumoto
2247e4f355
mruby-bigint (mpz_xor): simplify the code
2024-07-27 18:53:36 +09:00
Yukihiro "Matz" Matsumoto
b573a8430f
mruby-bigint (mpz_or): simplify the code
2024-07-27 18:50:09 +09:00
Yukihiro "Matz" Matsumoto
dea1cc18a6
mruby-bigint (mpz_and): simplify the code
2024-07-27 18:48:01 +09:00
Yukihiro "Matz" Matsumoto
bf081c3d3d
mruby-bigint (mrb_bint_and): further optimization for bint & int
2024-07-25 17:46:36 +09:00
Yukihiro "Matz" Matsumoto
99c078bb6b
mruby-bigint (mrb_bint_2comp): simplify using mpz_2comp()
2024-07-25 16:18:49 +09:00
Yukihiro "Matz" Matsumoto
3d69412ea5
mruby-bigint: Distinguish uzero_p(x) and x->sn == 0
...
The latter is a check for integers that have been set up (and disclosed to the
outer world), while the former is a check for integers that are being worked on.
2024-07-25 16:18:48 +09:00
Yukihiro "Matz" Matsumoto
93653dfd4c
mruby-bigint (uzero_p): add fast path
2024-07-25 16:18:48 +09:00
Yukihiro "Matz" Matsumoto
4ee7c8e021
mruby-bigint: rename uzero to uzero_p
...
Since uzero() is a predicate, and zero() is a function to assign zero to
mpz_t, it's confusion. Rename predicate uzero() to uzero_p() to follow
mruby naming convention.
2024-07-25 16:18:48 +09:00
Yukihiro "Matz" Matsumoto
88536ebe30
mruby-bigint (mpz_xor): support bit-wise xor with negative numbers; #6314
2024-07-25 16:18:48 +09:00
Yukihiro "Matz" Matsumoto
ee2eb6c87e
mruby-bigint (mpz_or): support bit-wise or with negative numbers; #6314
2024-07-25 16:18:48 +09:00
Yukihiro "Matz" Matsumoto
69a80c94b9
mruby-bigint (mpz_and): support bit-wise and with negative numbers
...
Negative integers are virtually considered as 2's compliment of the
absolute value of the corresponding number. It means `-1` is considered
as infinite sequence of `1` toward msb side. ref #6314
2024-07-25 16:18:48 +09:00
Yukihiro "Matz" Matsumoto
e3a459d5b9
mruby-bigint (mrb_bint_and): optimize bint & fixnum operation; ref #6314
2024-07-25 16:18:48 +09:00
Yukihiro "Matz" Matsumoto
c16aba9280
mruby-bigint: remove special handling of Float in bitwise operations
...
CRuby raises TypeError with float numbers as operands; ref #6314
2024-07-25 16:18:47 +09:00
John Bampton
de8a6fe787
Fix spelling
2024-07-13 00:21:53 +10:00
Yukihiro "Matz" Matsumoto
a77bc25a5f
mruby-sprintf: support dots expression of negative integer format
...
For specifiers assume unsigned integers, negative numbers show dots (..)
to indicate virtual infinite 1s at the MSB side of 2's compliment.
2024-07-09 11:13:55 +09:00
Yukihiro "Matz" Matsumoto
2488375a35
mruby-bigint (mpz_mod): move mpz_init() to avoid memory leak
2024-07-09 08:00:23 +09:00
Yukihiro "Matz" Matsumoto
681bcdbcd3
mruby-bigint: adjust local variable declarations
2024-05-26 07:38:34 +09:00
Yukihiro "Matz" Matsumoto
5257fe4333
mruby-bigint (mrb_bint_new_float): narrow the scope of variable 'f'
2024-01-03 07:23:55 +09:00
Yukihiro "Matz" Matsumoto
d632085b5b
mruby-bigint (udiv): narrow the scope of loop variable 'i'
2024-01-03 07:23:55 +09:00
Yukihiro "Matz" Matsumoto
7e865aec51
mruby-bigint/bigint.c: remove unused mrb_bint_new()
2023-08-08 11:24:14 +09:00
Yukihiro "Matz" Matsumoto
2f7f797473
remove extra spaces before ;
2023-05-22 12:05:35 +09:00
Yukihiro "Matz" Matsumoto
3d2cf0d9bf
mruby-bigint/bigint.c: fix int64/uint64 conversion
...
The functions were totally wrong in digit order and sign treatment. We
didn't notice since they are only called from mruby-time in the m64-i32
configuration.
2023-04-03 08:55:48 +09:00
Yukihiro "Matz" Matsumoto
d482eabfa2
mruby-bigint/bigint.c: int.pow(n,m) to take bigint as exponential
2023-03-31 08:26:47 +09:00
Yukihiro "Matz" Matsumoto
62c52d5a28
mruby-bigint/bigint.c: remove unreachable line
2023-03-30 08:18:27 +09:00
Yukihiro "Matz" Matsumoto
62a8ea7113
mruby-bigint/bigint.c: mrb_bint_add_d, mrb_bint_sub_d only take int
...
Where mrb_bint_add and mrb_bint_sub may take float numbers.
2023-03-15 19:09:02 +09:00
Yukihiro "Matz" Matsumoto
9a1e6760a8
mruby-bigint: add new functions mrb_bint_add_d, mrb_bint_sub_d
...
Those functions do not normalize the return value to avoid repeated
conversions between Bigints and (small) Integers.
2023-03-13 16:07:17 +09:00