diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-08-13 23:21:59 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-08-13 23:21:59 -0400 |
| commit | c8af1ac9c12073776fda6af7ae58f9d6e2d81e66 (patch) | |
| tree | 41f21373521121fd248b633c9053255848af1e39 /builtins | |
| parent | e56fd1aa94db77c6210c649c9cf8163678326355 (diff) | |
Tweak implementations of math opsbigints
Diffstat (limited to 'builtins')
| -rw-r--r-- | builtins/integers.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/builtins/integers.c b/builtins/integers.c index b7d96a90..0783f16d 100644 --- a/builtins/integers.c +++ b/builtins/integers.c @@ -142,9 +142,10 @@ public Int_t Int$slow_plus(Int_t x, Int_t y) { mpz_t result; mpz_init_set_int(result, x); if (y.small & 1) { - mpz_t y_mpz; - mpz_init_set_int(y_mpz, y); - mpz_add(result, result, y_mpz); + if (y.small < 0) + mpz_sub_ui(result, result, (uint64_t)(-(y.small >> 2))); + else + mpz_add_ui(result, result, (uint64_t)(y.small >> 2)); } else { mpz_add(result, result, *y.big); } @@ -155,9 +156,10 @@ public Int_t Int$slow_minus(Int_t x, Int_t y) { mpz_t result; mpz_init_set_int(result, x); if (y.small & 1) { - mpz_t y_mpz; - mpz_init_set_int(y_mpz, y); - mpz_sub(result, result, y_mpz); + if (y.small < 0) + mpz_add_ui(result, result, (uint64_t)(-(y.small >> 2))); + else + mpz_sub_ui(result, result, (uint64_t)(y.small >> 2)); } else { mpz_sub(result, result, *y.big); } @@ -167,13 +169,10 @@ public Int_t Int$slow_minus(Int_t x, Int_t y) { public Int_t Int$slow_times(Int_t x, Int_t y) { mpz_t result; mpz_init_set_int(result, x); - if (y.small & 1) { - mpz_t y_mpz; - mpz_init_set_int(y_mpz, y); - mpz_mul(result, result, y_mpz); - } else { + if (y.small & 1) + mpz_mul_si(result, result, y.small >> 2); + else mpz_mul(result, result, *y.big); - } return Int$from_mpz(result); } @@ -182,7 +181,7 @@ public Int_t Int$slow_divided_by(Int_t x, Int_t y) { mpz_init_set_int(result, x); if (y.small & 1) { mpz_t y_mpz; - mpz_init_set_int(y_mpz, y); + mpz_init_set_si(y_mpz, y.small >> 2); mpz_cdiv_q(result, result, y_mpz); } else { mpz_cdiv_q(result, result, *y.big); |
