<s> import math <EOL> from rpython . rlib . rfloat import round_away <EOL> from topaz . coerce import Coerce <EOL> from topaz . error import RubyError <EOL> from topaz . module import ClassDef <EOL> from topaz . modules . comparable import Comparable <EOL> from topaz . objects . objectobject import W_Object <EOL> class W_NumericObject ( W_Object ) : <EOL> classdef = ClassDef ( "<STR_LIT>" , W_Object . classdef ) <EOL> classdef . include_module ( Comparable ) <EOL> @ staticmethod <EOL> def retry_binop_coercing ( space , w_recv , w_arg , binop , raise_error = True ) : <EOL> w_ary = None <EOL> try : <EOL> w_ary = space . send ( w_recv , "<STR_LIT>" , [ w_arg ] ) <EOL> except RubyError as e : <EOL> if not space . is_kind_of ( e . w_value , space . w_StandardError ) : <EOL> raise <EOL> if raise_error : <EOL> raise space . error ( space . w_ArgumentError , <EOL> "<STR_LIT>" % ( <EOL> space . obj_to_s ( space . getclass ( w_recv ) ) , <EOL> space . obj_to_s ( space . getclass ( w_arg ) ) <EOL> ) <EOL> ) <EOL> if space . getclass ( w_ary ) is space . w_array : <EOL> ary = space . listview ( w_ary ) <EOL> if len ( ary ) == <NUM_LIT:2> : <EOL> return space . send ( ary [ <NUM_LIT:1> ] , binop , ary [ : <NUM_LIT:1> ] ) <EOL> elif raise_error : <EOL> raise space . error ( space . w_TypeError , "<STR_LIT>" ) <EOL> else : <EOL> return None <EOL> @ classdef . singleton_method ( "<STR_LIT>" ) <EOL> def method_allocate ( self , space ) : <EOL> return W_NumericObject ( space , self ) <EOL> @ classdef . method ( "<STR_LIT>" ) <EOL> def method_comparator ( self , space , w_other ) : <EOL> if self == w_other : <EOL> return space . newint ( <NUM_LIT:0> ) <EOL> else : <EOL> return space . w_nil <EOL> @ classdef . method ( "<STR_LIT>" ) <EOL> def method_lte ( self , space , w_other ) : <EOL> w_result = space . send ( self , "<STR_LIT>" , [ w_other ] ) <EOL> return space . newbool ( not ( w_result is space . w_nil or space . int_w ( w_result ) > <NUM_LIT:0> ) ) <EOL> @ classdef . method ( "<STR_LIT>" ) <EOL> def method_coerce ( self , space , w_other ) : <EOL> if space . getclass ( w_other ) is space . getclass ( self ) : <EOL> return space . newarray ( [ w_other , self ] ) <EOL> else : <EOL> return space . newarray ( [ space . send ( self , "<STR_LIT>" , [ w_other ] ) , self ] ) <EOL> @ classdef . method ( "<STR_LIT>" ) <EOL> def method_ceil ( self , space ) : <EOL> return space . newint ( int ( math . ceil ( Coerce . float ( space , self ) ) ) ) <EOL> @ classdef . method ( "<STR_LIT>" ) <EOL> def method_floor ( self , space ) : <EOL> return space . newint ( int ( math . floor ( Coerce . float ( space , self ) ) ) ) <EOL> @ classdef . method ( "<STR_LIT>" ) <EOL> def method_round ( self , space ) : <EOL> return space . newint ( int ( round_away ( Coerce . float ( space , self ) ) ) ) <EOL> @ classdef . method ( "<STR_LIT>" ) <EOL> def method_quo ( self , space ) : <EOL> raise space . error ( space . w_NotImplementedError , "<STR_LIT>" ) </s>
