Methods
Public Instance methods
Determines if another number is approximately equal within a given _n_th degree. Defaults to 100ths if the degree is not specified.
[ show source ]
# File lib/facets/core/numeric/approx.rb, line 6 def approx?( x, n=0.01 ) return(self == x) if n == 0 (self - x).abs <= n end
Returns the multiple ceil of a number.
[ show source ]
# File lib/facets/core/numeric/ceil_multiple.rb, line 8 def ceil_multiple(multiple) # gmosx: to_f is needed! # gmosx: IS THERE a more optimized way to do this? return ((self.to_f/multiple).ceil*multiple) end
Returns the distance between self an another value. This is the same as #- but it provides an alternative for common naming between variant classes.
4.distance(3) #=> 1
[ show source ]
# File lib/facets/core/numeric/distance.rb, line 10 def distance( other ) self - other end
[ show source ]
# File lib/facets/core/numeric/succ.rb, line 17 def pred(n=nil) n ||= 1 self - n end
[ show source ]
# File lib/facets/core/float/round_at.rb, line 21 def round_at(*args) self.to_f.round_at(*args) end
[ show source ]
# File lib/facets/core/float/round_to.rb, line 22 def round_to(*args) self.to_f.round_to(*args) end
Allows succ to take n increments.
3.succ(2) #=> 5
[ show source ]
# File lib/facets/core/numeric/succ.rb, line 8 def succ(n=nil) n ||= 1 self + n end
Provides a boolean interpretation of self. If self == 0 then false else true.
0.to_b #=> false 1.to_b #=> true 2.3.to_b #=> true
[ show source ]
# File lib/facets/core/numeric/to_b.rb, line 11 def to_b self == 0 ? false : true end