diff --git a/ext/symengine/symengine.c b/ext/symengine/symengine.c index b247cfb..8ca3d36 100644 --- a/ext/symengine/symengine.c +++ b/ext/symengine/symengine.c @@ -114,6 +114,9 @@ void Init_symengine() { c_zeta = rb_define_class_under(m_symengine, "Zeta", c_function); c_gamma = rb_define_class_under(m_symengine, "Gamma", c_function); + //Abs Class + c_abs = rb_define_class_under(m_symengine, "Abs", c_function); + //TrigFunction SubClasses c_sin = rb_define_class_under(m_symengine, "Sin", c_trig_function); c_cos = rb_define_class_under(m_symengine, "Cos", c_trig_function); diff --git a/ext/symengine/symengine.h b/ext/symengine/symengine.h index dfafce3..21259a6 100644 --- a/ext/symengine/symengine.h +++ b/ext/symengine/symengine.h @@ -25,6 +25,7 @@ VALUE c_lambertw; VALUE c_dirichlet_eta; VALUE c_zeta; VALUE c_gamma; +VALUE c_abs; VALUE c_sin; VALUE c_cos; VALUE c_tan; diff --git a/ext/symengine/symengine_utils.c b/ext/symengine/symengine_utils.c index a5938c6..a3ccbf1 100644 --- a/ext/symengine/symengine_utils.c +++ b/ext/symengine/symengine_utils.c @@ -101,6 +101,8 @@ VALUE Klass_of_Basic(const basic_struct *basic_ptr) { return c_mul; case SYMENGINE_POW: return c_pow; + case SYMENGINE_ABS: + return c_abs; case SYMENGINE_SIN: return c_sin; case SYMENGINE_COS: diff --git a/spec/functions_spec.rb b/spec/functions_spec.rb index 97e9f19..384f332 100644 --- a/spec/functions_spec.rb +++ b/spec/functions_spec.rb @@ -2,6 +2,26 @@ let(:pi) { SymEngine::PI } let(:e) { SymEngine::E } let(:x) { sym("x") } + let(:y) { sym("y") } + + context "Abs" do + context "with a symbol" do + subject { SymEngine::abs(x)} + it { is_expected.to be_a SymEngine::Abs } + end + context "with an integer" do + subject { SymEngine::abs(SymEngine(1))} + it { is_expected.to be_a SymEngine::Integer } + end + context "with a symbol addition" do + subject { SymEngine::abs(x+y) } + it { is_expected.to be_a SymEngine::Abs } + end + context "with a function of a symbol" do + subject { SymEngine::abs(SymEngine::sin(x)) } + it { is_expected.to be_a SymEngine::Abs } + end + end context '2*x' do [