Skip to content

Commit d57e5f5

Browse files
committed
Ntheory functions wrapped
1 parent 6cd53d1 commit d57e5f5

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

ext/symengine/ruby_ntheory.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,50 @@ VALUE cntheory_mod(VALUE self, VALUE operand1, VALUE operand2) {
5656
VALUE cntheory_quotient(VALUE self, VALUE operand1, VALUE operand2) {
5757
return cntheory_twoarg(ntheory_quotient, operand1, operand2);
5858
}
59+
60+
VALUE cntheory_fibonacci(VALUE self, VALUE operand1){
61+
basic_struct *cresult;
62+
VALUE result;
63+
64+
unsigned long cbasic_operand1;
65+
cbasic_operand1 = NUM2ULONG(operand1);
66+
67+
cresult = basic_new_heap();
68+
ntheory_fibonacci(cresult, cbasic_operand1);
69+
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult);
70+
71+
return result;
72+
}
73+
74+
VALUE cntheory_lucas(VALUE self, VALUE operand1){
75+
basic_struct *cresult;
76+
VALUE result;
77+
78+
unsigned long cbasic_operand1;
79+
cbasic_operand1 = NUM2ULONG(operand1);
80+
81+
cresult = basic_new_heap();
82+
ntheory_lucas(cresult, cbasic_operand1);
83+
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult);
84+
85+
return result;
86+
}
87+
88+
VALUE cntheory_binomial(VALUE self, VALUE operand1, VALUE operand2){
89+
basic_struct *cresult;
90+
VALUE result;
91+
92+
basic cbasic_operand1;
93+
basic_new_stack(cbasic_operand1);
94+
sympify(operand1, cbasic_operand1);
95+
96+
unsigned long cbasic_operand2;
97+
cbasic_operand2 = NUM2ULONG(operand2);
98+
99+
cresult = basic_new_heap();
100+
ntheory_binomial(cresult, cbasic_operand1, cbasic_operand2);
101+
result = Data_Wrap_Struct(Klass_of_Basic(cresult), NULL , cbasic_free_heap, cresult);
102+
basic_free_stack(cbasic_operand1);
103+
104+
return result;
105+
}

ext/symengine/ruby_ntheory.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ VALUE cntheory_lcm(VALUE self, VALUE operand1, VALUE operand2);
1616
VALUE cntheory_nextprime(VALUE self, VALUE operand1);
1717
VALUE cntheory_mod(VALUE self, VALUE operand1, VALUE operand2);
1818
VALUE cntheory_quotient(VALUE self, VALUE operand1, VALUE operand2);
19-
//VALUE cntheory_fibonacci(VALUE self, VALUE operand1);
20-
//VALUE cntheory_lucas(VALUE self, VALUE operand1);
21-
//VALUE cntheory_binomial(VALUE self, VALUE operand1, VALUE operand2);
19+
VALUE cntheory_fibonacci(VALUE self, VALUE operand1);
20+
VALUE cntheory_lucas(VALUE self, VALUE operand1);
21+
VALUE cntheory_binomial(VALUE self, VALUE operand1, VALUE operand2);
2222

2323
#endif //RUBY_NTHEORY_H_

ext/symengine/symengine.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ void Init_symengine() {
152152
rb_define_module_function(m_symengine, "nextprime", cntheory_nextprime, 1);
153153
rb_define_module_function(m_symengine, "mod", cntheory_mod, 2);
154154
rb_define_module_function(m_symengine, "quotient", cntheory_quotient, 2);
155-
//rb_define_module_function(m_symengine, "fibonacci", cntheory_fibonacci, 1);
156-
//rb_define_module_function(m_symengine, "lucas", cntheory_lucas, 1);
157-
//rb_define_module_function(m_symengine, "binomial", cntheory_binomial, 2);
155+
rb_define_module_function(m_symengine, "fibonacci", cntheory_fibonacci, 1);
156+
rb_define_module_function(m_symengine, "lucas", cntheory_lucas, 1);
157+
rb_define_module_function(m_symengine, "binomial", cntheory_binomial, 2);
158158

159159
}

0 commit comments

Comments
 (0)