Skip to content

Commit f23599d

Browse files
committed
Merge pull request #50 from rajithv/abs
Abs
2 parents f3d3821 + 106b052 commit f23599d

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

ext/symengine/symengine.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ void Init_symengine() {
114114
c_zeta = rb_define_class_under(m_symengine, "Zeta", c_function);
115115
c_gamma = rb_define_class_under(m_symengine, "Gamma", c_function);
116116

117+
//Abs Class
118+
c_abs = rb_define_class_under(m_symengine, "Abs", c_function);
119+
117120
//TrigFunction SubClasses
118121
c_sin = rb_define_class_under(m_symengine, "Sin", c_trig_function);
119122
c_cos = rb_define_class_under(m_symengine, "Cos", c_trig_function);

ext/symengine/symengine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ VALUE c_lambertw;
2525
VALUE c_dirichlet_eta;
2626
VALUE c_zeta;
2727
VALUE c_gamma;
28+
VALUE c_abs;
2829
VALUE c_sin;
2930
VALUE c_cos;
3031
VALUE c_tan;

ext/symengine/symengine_utils.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ VALUE Klass_of_Basic(const basic_struct *basic_ptr) {
101101
return c_mul;
102102
case SYMENGINE_POW:
103103
return c_pow;
104+
case SYMENGINE_ABS:
105+
return c_abs;
104106
case SYMENGINE_SIN:
105107
return c_sin;
106108
case SYMENGINE_COS:

spec/functions_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22
let(:pi) { SymEngine::PI }
33
let(:e) { SymEngine::E }
44
let(:x) { sym("x") }
5+
let(:y) { sym("y") }
6+
7+
context "Abs" do
8+
context "with a symbol" do
9+
subject { SymEngine::abs(x)}
10+
it { is_expected.to be_a SymEngine::Abs }
11+
end
12+
context "with an integer" do
13+
subject { SymEngine::abs(SymEngine(1))}
14+
it { is_expected.to be_a SymEngine::Integer }
15+
end
16+
context "with a symbol addition" do
17+
subject { SymEngine::abs(x+y) }
18+
it { is_expected.to be_a SymEngine::Abs }
19+
end
20+
context "with a function of a symbol" do
21+
subject { SymEngine::abs(SymEngine::sin(x)) }
22+
it { is_expected.to be_a SymEngine::Abs }
23+
end
24+
end
525

626
context '2*x' do
727
[

0 commit comments

Comments
 (0)