-
Notifications
You must be signed in to change notification settings - Fork 15
evalf ruby wrapper #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b6a2b45
evals ruby wrapper
rajithv 2f716e1
evalf specs for Ruby Wrapper
rajithv 81a0d7a
Changed symengine version
rajithv a8e3dde
Fixes #57
rajithv 7613e7c
Merge branch 'evals' of https://github.com/rajithv/symengine.rb into …
rajithv bb29a1b
Update ruby_utils.h - removed cbasic_operand
rajithv d38b5c8
Default values for evalf, .abs object method
rajithv 00d5633
comparisons for Number class
rajithv c7ef759
Changed spec and fixes for comparisons
rajithv cc88799
Merge branch 'evals' of https://github.com/rajithv/symengine.rb into …
rajithv 01d3743
ComplexMPC imaginary and real methods, evalf tests
rajithv 9e2be3f
Updated symengine version
rajithv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #include "ruby_complex_mpc.h" | ||
|
|
||
| #ifdef HAVE_SYMENGINE_MPC | ||
| VALUE ccomplex_mpc_real_part(VALUE self) | ||
| { | ||
| return function_onearg(complex_mpc_real_part, self); | ||
| } | ||
|
|
||
| VALUE ccomplex_mpc_imaginary_part(VALUE self) | ||
| { | ||
| return function_onearg(complex_mpc_imaginary_part, self); | ||
| } | ||
| #endif // HAVE_SYMENGINE_MPC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #ifndef RUBY_COMPLEX_MPC_H_ | ||
| #define RUBY_COMPLEX_MPC_H_ | ||
|
|
||
| #include <ruby.h> | ||
| #include <symengine/cwrapper.h> | ||
|
|
||
| #include "symengine.h" | ||
| #include "symengine_utils.h" | ||
|
|
||
| #ifdef HAVE_SYMENGINE_MPC | ||
| VALUE ccomplex_mpc_real_part(VALUE self); | ||
| VALUE ccomplex_mpc_imaginary_part(VALUE self); | ||
| #endif // HAVE_SYMENGINE_MPC | ||
|
|
||
| #endif // RUBY_COMPLEX_MPC_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #include "ruby_number.h" | ||
|
|
||
| int cnumber_comp(VALUE self, VALUE operand2) | ||
| { | ||
| basic cbasic_operand1; | ||
| basic cbasic_operand2; | ||
| basic_new_stack(cbasic_operand1); | ||
| basic_new_stack(cbasic_operand2); | ||
|
|
||
| basic cbasic_sub; | ||
| basic_new_stack(cbasic_sub); | ||
|
|
||
| sympify(self, cbasic_operand1); | ||
| sympify(operand2, cbasic_operand2); | ||
|
|
||
| if (is_a_Number(cbasic_operand2) == 0) { | ||
| rb_raise(rb_eTypeError, "Expected SymEngine::Number found %s ", | ||
| rb_obj_classname(operand2)); | ||
| } | ||
|
|
||
| basic_sub(cbasic_sub, cbasic_operand1, cbasic_operand2); | ||
|
|
||
| int sign = basic_number_sign(cbasic_sub); | ||
|
|
||
| basic_free_stack(cbasic_operand1); | ||
| basic_free_stack(cbasic_operand2); | ||
| basic_free_stack(cbasic_sub); | ||
|
|
||
| return sign; | ||
| } | ||
|
|
||
| VALUE cnumber_lt(VALUE self, VALUE operand2) | ||
| { | ||
| return cnumber_comp(self, operand2) == -1 ? Qtrue : Qfalse; | ||
| } | ||
|
|
||
| VALUE cnumber_gt(VALUE self, VALUE operand2) | ||
| { | ||
| return cnumber_comp(self, operand2) == 1 ? Qtrue : Qfalse; | ||
| } | ||
|
|
||
| VALUE cnumber_lt_e(VALUE self, VALUE operand2) | ||
| { | ||
| return cnumber_comp(self, operand2) == 1 ? Qfalse : Qtrue; | ||
| } | ||
|
|
||
| VALUE cnumber_gt_e(VALUE self, VALUE operand2) | ||
| { | ||
| return cnumber_comp(self, operand2) == -1 ? Qfalse : Qtrue; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #ifndef RUBY_NUMBER_H_ | ||
| #define RUBY_NUMBER_H_ | ||
|
|
||
| #include <ruby.h> | ||
| #include <symengine/cwrapper.h> | ||
|
|
||
| #include "symengine_utils.h" | ||
|
|
||
| int cnumber_comp(VALUE self, VALUE operand2); | ||
|
|
||
| VALUE cnumber_lt(VALUE self, VALUE operand2); | ||
|
|
||
| VALUE cnumber_gt(VALUE self, VALUE operand2); | ||
|
|
||
| VALUE cnumber_lt_e(VALUE self, VALUE operand2); | ||
|
|
||
| VALUE cnumber_gt_e(VALUE self, VALUE operand2); | ||
|
|
||
| #endif // RUBY_NUMBER_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,5 +9,10 @@ def inspect | |
| def free_symbols | ||
| pr_free_symbols.to_set | ||
| end | ||
|
|
||
| def abs | ||
| return SymEngine::abs(self) | ||
| end | ||
|
|
||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| describe 'SymEngine::evalf' do | ||
| context 'RealDouble values' do | ||
| subject { SymEngine::evalf(SymEngine::sin(SymEngine(2)), 53, true) } | ||
| it { is_expected.to be_a SymEngine::RealDouble } | ||
| it { is_expected.to be_within(1e-15).of(0.909297426825682) } | ||
| end | ||
| if SymEngine::HAVE_MPFR | ||
| context 'RealMPFR values' do | ||
| subject { SymEngine::evalf(SymEngine::PI * SymEngine(1963319607) - SymEngine(6167950454), 100, true) } | ||
| it { is_expected.to be_a SymEngine::RealMPFR } | ||
| it { is_expected.to be_within(SymEngine::RealMPFR.new("1e-41", 100)).of(SymEngine::RealMPFR.new("1.4973429143989597928099399837265e-10", 100)) } | ||
| end | ||
| end | ||
| context 'ComplexDouble values' do | ||
| subject { SymEngine::evalf(SymEngine::sin(1) * SymEngine::I, 53, false) } | ||
| it { is_expected.to be_a SymEngine::ComplexDouble } | ||
| its(:imaginary) { is_expected.to be_within(1e-15).of(0.841470984807897) } | ||
| end | ||
|
|
||
| if SymEngine::HAVE_MPC | ||
| context 'ComplexMPC values' do | ||
| subject { SymEngine::evalf(SymEngine::sin(1) * SymEngine::I, 100, false) } | ||
| it { is_expected.to be_a SymEngine::ComplexMPC } | ||
| its(:imaginary) { is_expected.to be_within(SymEngine::RealMPFR.new("1e-32", 100)).of(SymEngine::RealMPFR.new("0.84147098480789650665250232163005", 100)) } | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0c17ca9d88f25881c6d0ca382c26b2eb392b9b48 | ||
| bb18f1c1f4cbc29765fe1bcbd2dbe9345279b659 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to check here that
cbasic_operand2is also aNumber