Skip to content

Commit

Permalink
Merge pull request #525 from krekoten/float_equal_value
Browse files Browse the repository at this point in the history
Float#== calls 'other == self' if coercion fails
  • Loading branch information
alex committed Mar 20, 2013
2 parents 3edc8dc + bba2a1d commit 35ed208
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 0 additions & 1 deletion spec/tags/core/float/equal_value_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/tags/core/nil/to_f_tags.txt

This file was deleted.

16 changes: 15 additions & 1 deletion topaz/objects/floatobject.py
Expand Up @@ -8,7 +8,9 @@
from rpython.rlib.rfloat import (formatd, DTSF_ADD_DOT_0, DTSF_STR_PRECISION,
NAN, INFINITY)

from topaz.error import RubyError
from topaz.module import ClassDef
from topaz.objects.exceptionobject import W_ArgumentError
from topaz.objects.numericobject import W_NumericObject


Expand Down Expand Up @@ -119,10 +121,22 @@ def method(self, space, w_other):
return method
method_lt = new_bool_op(classdef, "<", operator.lt)
method_lte = new_bool_op(classdef, "<=", operator.le)
method_eq = new_bool_op(classdef, "==", operator.eq)
method_gt = new_bool_op(classdef, ">", operator.gt)
method_gte = new_bool_op(classdef, ">=", operator.ge)

@classdef.method("==")
def method_eq(self, space, w_other):
if space.is_kind_of(w_other, space.w_float):
return space.newbool(self.floatvalue == space.float_w(w_other))

try:
return W_NumericObject.retry_binop_coercing(space, self, w_other, "==")
except RubyError as e:
if isinstance(e.w_value, W_ArgumentError):
return space.send(w_other, space.newsymbol("=="), [self])
else:
raise

@classdef.method("<=>")
def method_comparator(self, space, w_other):
if space.is_kind_of(w_other, space.w_numeric):
Expand Down

0 comments on commit 35ed208

Please sign in to comment.