Class: Flt::UlpsTolerance
- Inherits:
-
FloatingTolerance
- Object
- Tolerance
- FloatingTolerance
- Flt::UlpsTolerance
- Defined in:
- lib/flt/tolerance.rb
Overview
Implementation of (floating) tolerances given in ULPs (units in the last place)
Instance Method Summary collapse
-
#initialize(n = nil, num_class = nil) ⇒ UlpsTolerance
constructor
A new instance of UlpsTolerance.
- #relative_to(x) ⇒ Object
- #relative_to_many(mode, *xs) ⇒ Object
- #to_s ⇒ Object
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.
421 422 423 424 425 426 427 428 |
# File 'lib/flt/tolerance.rb', line 421 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
432 433 434 435 436 |
# File 'lib/flt/tolerance.rb', line 432 def relative_to(x) context = x.class.context n = context.Num(@ulps) context.ulp(x)*n end |
#relative_to_many(mode, *xs) ⇒ Object
437 438 439 |
# File 'lib/flt/tolerance.rb', line 437 def relative_to_many(mode, *xs) xs.map{|x| relative_to(x)}.send(mode) end |