Class: Flt::UlpsTolerance

Inherits:
FloatingTolerance show all
Defined in:
lib/flt/tolerance.rb

Overview

Implementation of (floating) tolerances given in ULPs (units in the last place)

Instance Method Summary collapse

Methods inherited from FloatingTolerance

float_minimum_normalized_fraction, ref_adjusted_exp

Methods inherited from Tolerance

#[], big_epsilon, bits, #cast_value, decimals, define_sugar, #descr_value, digits, epsilon, #eq?, #equal_to?, #greater_than?, #gt?, #integer, #integer?, #less_than?, #lt?, #seq?, #value, #zero?

Constructor Details

#initialize(n = nil, num_class = nil) ⇒ UlpsTolerance

Returns a new instance of UlpsTolerance.



426
427
428
429
430
431
432
433
# File 'lib/flt/tolerance.rb', line 426

def initialize(n=nil, num_class=nil)
  @ulps = n || 1
  num_class ||= Float
  context = num_class.context
  unit = context.Num(1)
  n = context.Num(@ulps)
  super(context.ulp(unit)*n)
end

Instance Method Details

#relative_to(x) ⇒ Object



437
438
439
440
441
# File 'lib/flt/tolerance.rb', line 437

def relative_to(x)
  context = x.class.context
  n = context.Num(@ulps)
  context.ulp(x)*n
end

#relative_to_many(mode, *xs) ⇒ Object



442
443
444
# File 'lib/flt/tolerance.rb', line 442

def relative_to_many(mode, *xs)
  xs.map{|x| relative_to(x)}.send(mode)
end

#to_sObject



434
435
436
# File 'lib/flt/tolerance.rb', line 434

def to_s
  "#{@ulps} ulp#{(!@ulps.kind_of?(Numeric) || (@ulps > 1)) ? 's' : ''}"
end