Skip to content

Commit 515b715

Browse files
committed
Fixed incompatibility of mod operation
1 parent 719470c commit 515b715

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

ext/symengine/ruby_ntheory.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ VALUE cntheory_lcm(VALUE self, VALUE operand1, VALUE operand2) {
1313
}
1414

1515
VALUE cntheory_mod(VALUE self, VALUE operand1, VALUE operand2) {
16-
return function_twoarg(ntheory_mod, operand1, operand2);
16+
VALUE ans = function_twoarg(ntheory_mod, operand1, operand2);
17+
VALUE ans1 = cbasic_add(ans, operand2);
18+
return function_twoarg(ntheory_mod, ans1, operand2);
1719
}
1820

1921
VALUE cntheory_quotient(VALUE self, VALUE operand1, VALUE operand2) {

ext/symengine/ruby_ntheory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <symengine/cwrapper.h>
66

77
#include "symengine.h"
8+
#include "ruby_basic.h"
89
#include "symengine_utils.h"
910

1011
VALUE cntheory_onearg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*), VALUE operand1);

ext/symengine/symengine_utils.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ VALUE function_onearg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*), VA
128128
return result;
129129
}
130130

131-
VALUE function_twoarg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*), VALUE operand1, VALUE operand2) {
131+
VALUE function_twoarg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*),
132+
VALUE operand1, VALUE operand2) {
132133
basic_struct *cresult;
133134
VALUE result;
134135

ext/symengine/symengine_utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ VALUE Klass_of_Basic(const basic_struct *basic_ptr);
1212
//Returns the result from the function pointed by cwfunc_ptr: for one argument functions
1313
VALUE function_onearg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*), VALUE operand1);
1414
//Returns the result from the function pointed by cwfunc_ptr: for two argument functions
15-
VALUE function_twoarg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*), VALUE operand1, VALUE operand2);
15+
VALUE function_twoarg(void (*cwfunc_ptr)(basic_struct*, const basic_struct*, const basic_struct*),
16+
VALUE operand1, VALUE operand2);
1617

1718
//Obtains the value from Ruby Fixnum or Bignum to an already allocated basic_struct
1819
#define GET_SYMINTFROMVAL(num_value, this) { \

spec/ntheory_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@
4040
expect(f).to eql(1)
4141
end
4242
end
43+
context '-5 mod -4' do
44+
it 'returns -1' do
45+
f = SymEngine::mod(-5, -4)
46+
expect(f).to eql(-1)
47+
end
48+
end
49+
context '5 mod -4' do
50+
it 'returns -3' do
51+
f = SymEngine::mod(5, -4)
52+
expect(f).to eql(-3)
53+
end
54+
end
55+
context '-5 mod 4' do
56+
it 'returns 3' do
57+
f = SymEngine::mod(-5, 4)
58+
expect(f).to eql(3)
59+
end
60+
end
4361
end
4462

4563
describe '#quotient' do

0 commit comments

Comments
 (0)