|
1 | 1 | #include "ruby_ntheory.h" |
2 | 2 |
|
3 | | -VALUE cntheory_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 cntheory_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 | 3 | VALUE cntheory_nextprime(VALUE self, VALUE operand1) { |
41 | | - return cntheory_onearg(ntheory_nextprime, operand1); |
| 4 | + return function_onearg(ntheory_nextprime, operand1); |
42 | 5 | } |
43 | 6 |
|
44 | 7 | VALUE cntheory_gcd(VALUE self, VALUE operand1, VALUE operand2) { |
45 | | - return cntheory_twoarg(ntheory_gcd, operand1, operand2); |
| 8 | + return function_twoarg(ntheory_gcd, operand1, operand2); |
46 | 9 | } |
47 | 10 |
|
48 | 11 | VALUE cntheory_lcm(VALUE self, VALUE operand1, VALUE operand2) { |
49 | | - return cntheory_twoarg(ntheory_lcm, operand1, operand2); |
| 12 | + return function_twoarg(ntheory_lcm, operand1, operand2); |
50 | 13 | } |
51 | 14 |
|
52 | 15 | VALUE cntheory_mod(VALUE self, VALUE operand1, VALUE operand2) { |
53 | | - return cntheory_twoarg(ntheory_mod, operand1, operand2); |
| 16 | + return function_twoarg(ntheory_mod, operand1, operand2); |
54 | 17 | } |
55 | 18 |
|
56 | 19 | VALUE cntheory_quotient(VALUE self, VALUE operand1, VALUE operand2) { |
57 | | - return cntheory_twoarg(ntheory_quotient, operand1, operand2); |
| 20 | + return function_twoarg(ntheory_quotient, operand1, operand2); |
58 | 21 | } |
59 | 22 |
|
60 | 23 | VALUE cntheory_fibonacci(VALUE self, VALUE operand1){ |
|
0 commit comments