|
| 1 | +#include "ruby_ntheory.h" |
| 2 | + |
| 3 | +VALUE cfunction_onearg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*), VALUE operand1) { |
| 4 | + basic_struct *cresult; |
| 5 | + VALUE result; |
| 6 | + |
| 7 | + basic cbasic_operand1; |
| 8 | + basic_new_stack(cbasic_operand1); |
| 9 | + sympify(operand1, cbasic_operand1); |
| 10 | + |
| 11 | + cresult = basic_new_heap(); |
| 12 | + cwfunc_ptr(cresult, cbasic_operand1); |
| 13 | + result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); |
| 14 | + basic_free_stack(cbasic_operand1); |
| 15 | + |
| 16 | + return result; |
| 17 | +} |
| 18 | + |
| 19 | +VALUE cfunction_twoarg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*), VALUE operand1, VALUE operand2) { |
| 20 | + basic_struct *cresult; |
| 21 | + VALUE result; |
| 22 | + |
| 23 | + basic cbasic_operand1; |
| 24 | + basic_new_stack(cbasic_operand1); |
| 25 | + sympify(operand1, cbasic_operand1); |
| 26 | + |
| 27 | + basic cbasic_operand2; |
| 28 | + basic_new_stack(cbasic_operand2); |
| 29 | + sympify(operand2, cbasic_operand2); |
| 30 | + |
| 31 | + cresult = basic_new_heap(); |
| 32 | + cwfunc_ptr(cresult, cbasic_operand1, cbasic_operand2); |
| 33 | + result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); |
| 34 | + basic_free_stack(cbasic_operand1); |
| 35 | + basic_free_stack(cbasic_operand2); |
| 36 | + |
| 37 | + return result; |
| 38 | +} |
| 39 | + |
| 40 | +VALUE cfunction_nextprime(VALUE self, VALUE operand1) { |
| 41 | + return cfunction_onearg(nthoery_gcd, operand1); |
| 42 | +} |
| 43 | + |
| 44 | +VALUE cfunction_gcd(VALUE self, VALUE operand1, VALUE operand2) { |
| 45 | + return cfunction_twoarg(ntheory_gcd, operand1, operand2); |
| 46 | +} |
| 47 | + |
| 48 | +VALUE cfunction_lcm(VALUE self, VALUE operand1, VALUE operand2) { |
| 49 | + return cfunction_twoarg(ntheory_lcm, operand1, operand2); |
| 50 | +} |
| 51 | + |
| 52 | +VALUE cfunction_mod(VALUE self, VALUE operand1, VALUE operand2) { |
| 53 | + return cfunction_twoarg(ntheory_mod, operand1, operand2); |
| 54 | +} |
| 55 | + |
| 56 | +VALUE cfunction_quotient(VALUE self, VALUE operand1, VALUE operand2) { |
| 57 | + return cfunction_twoarg(ntheory_quotient, operand1, operand2); |
| 58 | +} |
0 commit comments