|
| 1 | +#include "ruby_ntheory.h" |
| 2 | + |
| 3 | +VALUE cntheory_nextprime(VALUE self, VALUE operand1) { |
| 4 | + return function_onearg(ntheory_nextprime, operand1); |
| 5 | +} |
| 6 | + |
| 7 | +VALUE cntheory_gcd(VALUE self, VALUE operand1, VALUE operand2) { |
| 8 | + return function_twoarg(ntheory_gcd, operand1, operand2); |
| 9 | +} |
| 10 | + |
| 11 | +VALUE cntheory_lcm(VALUE self, VALUE operand1, VALUE operand2) { |
| 12 | + return function_twoarg(ntheory_lcm, operand1, operand2); |
| 13 | +} |
| 14 | + |
| 15 | +VALUE cntheory_mod(VALUE self, VALUE operand2) { |
| 16 | + VALUE ans = function_twoarg(ntheory_mod, self, operand2); |
| 17 | + VALUE ans1 = cbasic_add(ans, operand2); |
| 18 | + return function_twoarg(ntheory_mod, ans1, operand2); |
| 19 | +} |
| 20 | + |
| 21 | +VALUE cntheory_quotient(VALUE self, VALUE operand1, VALUE operand2) { |
| 22 | + return function_twoarg(ntheory_quotient, operand1, operand2); |
| 23 | +} |
| 24 | + |
| 25 | +VALUE cntheory_fibonacci(VALUE self, VALUE operand1){ |
| 26 | + basic_struct *cresult; |
| 27 | + VALUE result; |
| 28 | + |
| 29 | + unsigned long cbasic_operand1; |
| 30 | + cbasic_operand1 = NUM2ULONG(operand1); |
| 31 | + |
| 32 | + cresult = basic_new_heap(); |
| 33 | + ntheory_fibonacci(cresult, cbasic_operand1); |
| 34 | + result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); |
| 35 | + |
| 36 | + return result; |
| 37 | +} |
| 38 | + |
| 39 | +VALUE cntheory_lucas(VALUE self, VALUE operand1){ |
| 40 | + basic_struct *cresult; |
| 41 | + VALUE result; |
| 42 | + |
| 43 | + unsigned long cbasic_operand1; |
| 44 | + cbasic_operand1 = NUM2ULONG(operand1); |
| 45 | + |
| 46 | + cresult = basic_new_heap(); |
| 47 | + ntheory_lucas(cresult, cbasic_operand1); |
| 48 | + result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); |
| 49 | + |
| 50 | + return result; |
| 51 | +} |
| 52 | + |
| 53 | +VALUE cntheory_binomial(VALUE self, VALUE operand1, VALUE operand2){ |
| 54 | + basic_struct *cresult; |
| 55 | + VALUE result; |
| 56 | + |
| 57 | + basic cbasic_operand1; |
| 58 | + basic_new_stack(cbasic_operand1); |
| 59 | + sympify(operand1, cbasic_operand1); |
| 60 | + |
| 61 | + unsigned long cbasic_operand2; |
| 62 | + cbasic_operand2 = NUM2ULONG(operand2); |
| 63 | + |
| 64 | + cresult = basic_new_heap(); |
| 65 | + ntheory_binomial(cresult, cbasic_operand1, cbasic_operand2); |
| 66 | + result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult); |
| 67 | + basic_free_stack(cbasic_operand1); |
| 68 | + |
| 69 | + return result; |
| 70 | +} |
0 commit comments