Skip to content
Permalink
Browse files

Merge pull request #525 from krekoten/float_equal_value

Float#== calls 'other == self' if coercion fails
  • Loading branch information
alex committed Mar 20, 2013
2 parents 3edc8dc + bba2a1d commit 35ed208d65d210564a9dfe2059ef8de1b3fabe2e
Showing with 15 additions and 3 deletions.
  1. +0 −1 spec/tags/core/float/equal_value_tags.txt
  2. +0 −1 spec/tags/core/nil/to_f_tags.txt
  3. +15 −1 topaz/objects/floatobject.py

This file was deleted.

This file was deleted.

@@ -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


@@ -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):

0 comments on commit 35ed208

Please sign in to comment.
You can’t perform that action at this time.