summaryrefslogtreecommitdiff
path: root/complex.c
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-14 01:16:44 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-14 01:16:44 +0000
commite4b3a817697a2ac04ecf7e6b4e62e92c54161236 (patch)
tree5809e4e36f761a07aab1fe7252840f8b625d153c /complex.c
parent19416601a0af3b7c99a570ae6993cb29e4360e64 (diff)
* complex.c (f_{add,mul,sub}): omitted some shortcuts for preserve
signed zero anyway. * complex.c (nucomp_negate): new. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19335 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'complex.c')
-rw-r--r--complex.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/complex.c b/complex.c
index 4d7dc2901c..07b8223561 100644
--- a/complex.c
+++ b/complex.c
@@ -64,13 +64,17 @@ m_##n(VALUE x, VALUE y)\
return rb_funcall(rb_mMath, id_##n, 2, x, y);\
}
+#define PRESERVE_SIGNEDZERO
+
inline static VALUE
f_add(VALUE x, VALUE y)
{
+#ifndef PRESERVE_SIGNEDZERO
if (FIXNUM_P(y) && FIX2LONG(y) == 0)
return x;
else if (FIXNUM_P(x) && FIX2LONG(x) == 0)
return y;
+#endif
return rb_funcall(x, '+', 1, y);
}
@@ -117,6 +121,7 @@ binop(mod, '%')
inline static VALUE
f_mul(VALUE x, VALUE y)
{
+#ifndef PRESERVE_SIGNEDZERO
if (FIXNUM_P(y)) {
long iy = FIX2LONG(y);
if (iy == 0) {
@@ -135,14 +140,17 @@ f_mul(VALUE x, VALUE y)
else if (ix == 1)
return y;
}
+#endif
return rb_funcall(x, '*', 1, y);
}
inline static VALUE
f_sub(VALUE x, VALUE y)
{
+#ifndef PRESERVE_SIGNEDZERO
if (FIXNUM_P(y) && FIX2LONG(y) == 0)
return x;
+#endif
return rb_funcall(x, '-', 1, y);
}
@@ -524,6 +532,14 @@ nucomp_image(VALUE self)
}
static VALUE
+nucomp_negate(VALUE self)
+{
+ get_dat1(self);
+ return f_complex_new2(CLASS_OF(self),
+ f_negate(dat->real), f_negate(dat->image));
+}
+
+static VALUE
nucomp_add(VALUE self, VALUE other)
{
if (k_complex_p(other)) {
@@ -1393,6 +1409,7 @@ Init_Complex(void)
rb_define_method(rb_cComplex, "image", nucomp_image, 0);
rb_define_method(rb_cComplex, "imag", nucomp_image, 0);
+ rb_define_method(rb_cComplex, "-@", nucomp_negate, 0);
rb_define_method(rb_cComplex, "+", nucomp_add, 1);
rb_define_method(rb_cComplex, "-", nucomp_sub, 1);
rb_define_method(rb_cComplex, "*", nucomp_mul, 1);
@@ -1474,3 +1491,9 @@ Init_Complex(void)
rb_define_const(rb_cComplex, "I",
f_complex_new_bang2(rb_cComplex, ZERO, ONE));
}
+
+/*
+Local variables:
+c-file-style: "ruby"
+end:
+*/