lib/flt/support.rb in flt-1.0.0 vs lib/flt/support.rb in flt-1.1.0

- old
+ new

@@ -481,13 +481,13 @@ else if context.num_class == Float float = true context = BinNum::FloatContext end - x = context.num_class.context(context) do |context| - context.rounding = round_mode - Num.convert_exact(Num[eb].Num(sign, f, e), context.num_class, context) + x = context.num_class.context(context) do |loca_context| + local_context.rounding = round_mode + Num.convert_exact(Num[eb].Num(sign, f, e), local_context.num_class, local_context) end if float x = x.to_f else x = context.normalize(x) unless context.exact? @@ -591,11 +591,11 @@ e = Float::MIN_EXP e -= Float::MANT_DIG unless normalized min_exp = (e*Math.log(Float::RADIX)/Math.log(base)).ceil @float_min_max_exp_values[k] = min_max = [min_exp, max_exp] end - min_max.map{|e| e - 1} # adjust + min_max.map{|exp| exp - 1} # adjust end end def compare(m, x, y, context) ret = nil @@ -1328,8 +1328,27 @@ end # AuxiliarFunctions end # Support +end # Flt - -end # Flt \ No newline at end of file +# The math method of context needs instance_exec to pass parameters to the blocks evaluated +# with a modified self (pointing to a context object.) intance_exec is available in Ruby 1.9.1 and +# is also defined by ActiveRecord. Here we use Mauricio Fernández implementation if it is not +# available. +class Object + unless defined? instance_exec + module InstanceExecHelper; end + include InstanceExecHelper + def instance_exec(*args, &block) # !> method redefined; discarding old instance_exec + mname = "__instance_exec_#{Thread.current.object_id.abs}_#{object_id.abs}" + InstanceExecHelper.module_eval{ define_method(mname, &block) } + begin + ret = send(mname, *args) + ensure + InstanceExecHelper.module_eval{ undef_method(mname) } rescue nil + end + ret + end + end +end