aboutsummaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-24 13:59:06 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-24 13:59:06 +0000
commited00379c79dcfd50867befa0a13f015aff695c00 (patch)
treeb22263a876cbaef75436becfe091c9a5d9c2e451 /numeric.c
parent3bcb10ad2a11f60ec8458ad24f64b0ec97a816cc (diff)
downloadruby-ed00379c79dcfd50867befa0a13f015aff695c00.tar.gz
numeric.c: calculate complex numbers
* numeric.c (fix_plus, fix_mul): calculate complex numbers for commutative operations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/numeric.c b/numeric.c
index 2474b49114..1950754f60 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2864,6 +2864,10 @@ fix_plus(VALUE x, VALUE y)
else if (RB_TYPE_P(y, T_FLOAT)) {
return DBL2NUM((double)FIX2LONG(x) + RFLOAT_VALUE(y));
}
+ else if (RB_TYPE_P(y, T_COMPLEX)) {
+ VALUE rb_nucomp_add(VALUE, VALUE);
+ return rb_nucomp_add(y, x);
+ }
else {
return rb_num_coerce_bin(x, y, '+');
}
@@ -2953,6 +2957,10 @@ fix_mul(VALUE x, VALUE y)
else if (RB_TYPE_P(y, T_FLOAT)) {
return DBL2NUM((double)FIX2LONG(x) * RFLOAT_VALUE(y));
}
+ else if (RB_TYPE_P(y, T_COMPLEX)) {
+ VALUE rb_nucomp_mul(VALUE, VALUE);
+ return rb_nucomp_mul(y, x);
+ }
else {
return rb_num_coerce_bin(x, y, '*');
}