Skip to content

Commit 3042fe1

Browse files
authored
Fix complex addition handling in C extension (#50)
Fix the sum path for complex initial values, which was implemented but not functioning correctly.
1 parent 45f4fed commit 3042fe1

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

ext/enumerable/statistics/extension/statistics.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ complex_add(VALUE self, VALUE other)
163163

164164
real = f_add(RCOMPLEX(self)->real, other);
165165

166-
return complex_new(CLASS_OF(self), real, RCOMPLEX(other)->imag);
166+
return complex_new(CLASS_OF(self), real, RCOMPLEX(self)->imag);
167167
}
168168
return rb_num_coerce_bin(self, other, idPLUS);
169169
}

spec/array_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
require 'delegate'
44

55
RSpec.describe Array do
6+
describe '#sum' do
7+
it 'sums with a complex init' do
8+
expect([1, 2, 3].sum(Complex(1, 2))).to eq(Complex(7, 2))
9+
end
10+
end
11+
612
describe '#mean' do
713
let(:ary) { [] }
814
let(:block) { nil }

0 commit comments

Comments
 (0)