diff options
author | Matthias Andreas Benkard <matthias@benkard.de> | 2008-06-15 22:28:54 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <matthias@benkard.de> | 2008-06-15 22:28:54 +0200 |
commit | 0f26b71433c96b1705279a96add89b325bd58efb (patch) | |
tree | bc8d3be6aa6dde29dee3a1738f6900cb05bcc1ac | |
parent | 47da9c1e9ac25b3248a808f4519e2c64ecb8e2b4 (diff) |
MLKInteger: Generalise the DEFINE_MPZ_OPERATION macro.
-rw-r--r-- | MLKInteger.m | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/MLKInteger.m b/MLKInteger.m index b9e9bf4..e659348 100644 --- a/MLKInteger.m +++ b/MLKInteger.m @@ -53,24 +53,31 @@ base:base]); } -#define DEFINE_MPZ_OPERATION(selector, mpzop) \ - -(MLKInteger *) selector (MLKInteger *)arg \ - { \ - mpz_t mpz; \ - MLKInteger *result; \ - \ - mpz_init (mpz); \ - mpzop (mpz, self->value, arg->value); \ - result = [MLKInteger integerWithMPZ:mpz]; \ - mpz_clear (mpz); \ - \ - return result; \ +#define DEFINE_GMP_OPERATION(SIGNATURE, TYPE, GMPOP, OBJTYPE, CONSTRUCTOR) \ + -(OBJTYPE *) SIGNATURE \ + { \ + TYPE##_t mpval; \ + OBJTYPE *result; \ + \ + TYPE##_init (mpval); \ + GMPOP; \ + result = [OBJTYPE CONSTRUCTOR mpval]; \ + TYPE##_clear (mpval); \ + \ + return result; \ } -DEFINE_MPZ_OPERATION (add:, mpz_add) -DEFINE_MPZ_OPERATION (subtract:, mpz_sub) -DEFINE_MPZ_OPERATION (multiplyWith:, mpz_mul) -DEFINE_MPZ_OPERATION (divideBy:, mpz_div) +#define DEFINE_MPZ_TWOARG_OPERATION(SELECTOR, GMPFUN) \ + DEFINE_GMP_OPERATION (SELECTOR (MLKInteger *)arg, \ + mpz, \ + GMPFUN (mpval, self->value, arg->value), \ + MLKInteger, \ + integerWithMPZ:) + +DEFINE_MPZ_TWOARG_OPERATION (add:, mpz_add) +DEFINE_MPZ_TWOARG_OPERATION (subtract:, mpz_add) +DEFINE_MPZ_TWOARG_OPERATION (multiplyWith:, mpz_add) +DEFINE_MPZ_TWOARG_OPERATION (divideBy:, mpz_add) -(int) intValue { |