class Float

Constants

INFINITY
NAN

Public Instance Methods

dup() click to toggle source
# File lib/backports/2.4.0/float/dup.rb, line 2
def dup
  self
end
next_float() click to toggle source
# File lib/backports/2.2.0/float/next_float.rb, line 5
def next_float
  return Float::INFINITY if self == Float::INFINITY
  r = Backports.integer_to_float(Backports.float_to_integer(self)+1)
  r == 0 ? -0.0 : r # Map +0.0 to -0.0
end
prev_float() click to toggle source
# File lib/backports/2.2.0/float/prev_float.rb, line 6
def prev_float
  return -Float::INFINITY if self == -Float::INFINITY
  Backports.integer_to_float(Backports.float_to_integer(self)-1)
end
round_with_digits(ndigits=0) click to toggle source
# File lib/backports/1.9.1/float/round.rb, line 6
def round_with_digits(ndigits=0)
  ndigits = Backports::coerce_to_int(ndigits)
  case
  when ndigits == 0
    round_without_digits
  when ndigits < 0
    p = 10 ** -ndigits
    p > abs ? 0 : (self / p).round * p
  else
    p = 10 ** ndigits
    prod = self * p
    prod.infinite? || prod.nan? ? self : prod.round.to_f / p
  end
end