summaryrefslogtreecommitdiff
path: root/complex.c
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-15 04:20:46 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-15 04:20:46 +0000
commit05ac51d2258b7681df7484a4e0ca787de84c7af9 (patch)
tree67826d260d299bc16de16604fc7e48b85e353638 /complex.c
parent0675246ba6456ee4bad43d0fa13b401ce92d6309 (diff)
* complex.c (nucomp_eql_p): new.
* complex.c (nucomp_hash): should use hash values of the elements. * rational.c (nurat_hash): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'complex.c')
-rw-r--r--complex.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/complex.c b/complex.c
index 1d31f6a08f..454bf1351f 100644
--- a/complex.c
+++ b/complex.c
@@ -23,7 +23,7 @@ VALUE rb_cComplex;
static ID id_Unify, id_abs, id_abs2, id_arg, id_cmp, id_conjugate,
id_convert, id_denominator, id_divmod, id_equal_p, id_exact_p, id_expt,
- id_floor, id_format, id_idiv, id_inspect, id_negate, id_new, id_new_bang,
+ id_floor, id_hash, id_idiv, id_inspect, id_negate, id_new, id_new_bang,
id_numerator, id_polar, id_quo, id_scalar_p, id_to_f, id_to_i, id_to_r,
id_to_s, id_truncate;
@@ -163,6 +163,7 @@ fun1(conjugate)
fun1(denominator)
fun1(exact_p)
fun1(floor)
+fun1(hash)
fun1(inspect)
fun1(negate)
fun1(numerator)
@@ -847,7 +848,21 @@ static VALUE
nucomp_hash(VALUE self)
{
get_dat1(self);
- return f_xor(dat->real, dat->image);
+ return f_xor(f_hash(dat->real), f_hash(dat->image));
+}
+
+static VALUE
+nucomp_eql_p(VALUE self, VALUE other)
+{
+ if (k_complex_p(other)) {
+ get_dat2(self, other);
+
+ return f_boolcast((CLASS_OF(adat->real) == CLASS_OF(bdat->real)) &&
+ (CLASS_OF(adat->image) == CLASS_OF(bdat->image)) &&
+ f_equal_p(self, other));
+
+ }
+ return Qfalse;
}
#ifndef HAVE_SIGNBIT
@@ -1354,7 +1369,7 @@ Init_Complex(void)
id_exact_p = rb_intern("exact?");
id_expt = rb_intern("**");
id_floor = rb_intern("floor");
- id_format = rb_intern("format");
+ id_hash = rb_intern("hash");
id_idiv = rb_intern("div");
id_inspect = rb_intern("inspect");
id_negate = rb_intern("-@");
@@ -1451,6 +1466,7 @@ Init_Complex(void)
rb_define_method(rb_cComplex, "denominator", nucomp_denominator, 0);
rb_define_method(rb_cComplex, "hash", nucomp_hash, 0);
+ rb_define_method(rb_cComplex, "eql?", nucomp_eql_p, 1);
rb_define_method(rb_cComplex, "to_s", nucomp_to_s, 0);
rb_define_method(rb_cComplex, "inspect", nucomp_inspect, 0);