Skip to content

Commit 5a58b37

Browse files
committed
Merge branch 'master' of http://github.com/symengine/symengine.rb into double2
2 parents 940a144 + 6d9b596 commit 5a58b37

File tree

6 files changed

+12
-47
lines changed

6 files changed

+12
-47
lines changed

ext/symengine/ruby_complex.c

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,9 @@
11
#include "ruby_complex.h"
22

33
VALUE ccomplex_real_part(VALUE self) {
4-
basic_struct *c_result = basic_new_heap();
5-
6-
basic cbasic_operand;
7-
basic_new_stack(cbasic_operand);
8-
9-
VALUE result;
10-
11-
sympify(self, cbasic_operand);
12-
complex_real_part(c_result, cbasic_operand);
13-
14-
result = Data_Wrap_Struct(Klass_of_Basic(c_result), NULL, cbasic_free_heap, c_result);
15-
16-
basic_free_stack(cbasic_operand);
17-
18-
return result;
4+
return function_onearg(complex_real_part, self);
195
}
206

217
VALUE ccomplex_imaginary_part(VALUE self) {
22-
basic_struct *c_result = basic_new_heap();
23-
24-
basic cbasic_operand;
25-
basic_new_stack(cbasic_operand);
26-
27-
VALUE result;
28-
29-
sympify(self, cbasic_operand);
30-
complex_imaginary_part(c_result, cbasic_operand);
31-
32-
result = Data_Wrap_Struct(Klass_of_Basic(c_result), NULL, cbasic_free_heap, c_result);
33-
34-
basic_free_stack(cbasic_operand);
35-
36-
return result;
8+
return function_onearg(complex_imaginary_part, self);
379
}

ext/symengine/ruby_constant.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,28 @@
11
#include "ruby_constant.h"
22

3-
VALUE cconstant_const(void (*cwfunc_ptr)(basic_struct*)) {
3+
VALUE cconstant_const(void (*cwfunc_ptr)(basic_struct*), VALUE klass) {
44
basic_struct *cresult;
55
VALUE result;
66

77
cresult = basic_new_heap();
88
cwfunc_ptr(cresult);
99

10-
result = Data_Wrap_Struct(c_constant, NULL, cbasic_free_heap, cresult);
10+
result = Data_Wrap_Struct(klass, NULL, cbasic_free_heap, cresult);
1111
return result;
1212
}
1313

1414
VALUE cconstant_pi() {
15-
return cconstant_const(basic_const_pi);
15+
return cconstant_const(basic_const_pi, c_constant);
1616
}
1717

1818
VALUE cconstant_e() {
19-
return cconstant_const(basic_const_E);
19+
return cconstant_const(basic_const_E, c_constant);
2020
}
2121

2222
VALUE cconstant_euler_gamma() {
23-
return cconstant_const(basic_const_EulerGamma);
23+
return cconstant_const(basic_const_EulerGamma, c_constant);
2424
}
2525

2626
VALUE cconstant_i() {
27-
basic_struct *cresult;
28-
VALUE result;
29-
30-
cresult = basic_new_heap();
31-
basic_const_I(cresult);
32-
33-
result = Data_Wrap_Struct(c_complex, NULL, cbasic_free_heap, cresult);
34-
return result;
27+
return cconstant_const(basic_const_I, c_complex);
3528
}

ext/symengine/ruby_constant.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "symengine.h"
88
#include "symengine_utils.h"
99

10-
VALUE cconstant_const(void (*cwfunc_ptr)(basic_struct*));
10+
VALUE cconstant_const(void (*cwfunc_ptr)(basic_struct*), VALUE klass);
1111

1212
VALUE cconstant_pi();
1313

lib/symengine/complex.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module SymEngine
22
class Complex
33
def to_c
4-
self.to_s.sub('I', 'i').sub('*','').gsub(' ','').to_c
4+
to_s.tr('I', 'i').delete(' *').to_c
55
end
66
end
77
end

spec/complex_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
describe SymEngine::Complex do
2-
context '#initialize' do
2+
context 'Convert to SymEngine types' do
33
context 'with a Complex' do
44
subject { SymEngine(Complex(2, 3)) }
55

spec/rational_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
describe SymEngine::Rational do
2-
context '#initialize' do
2+
context 'Convert to SymEngine types' do
33
context 'with a Rational' do
44
subject { SymEngine(Rational('2/3')) }
55

0 commit comments

Comments
 (0)