Class: Float
- Defined in:
- lib/backports/2.4.0/float/dup.rb,
lib/backports/1.9.1/float/round.rb,
lib/backports/2.2.0/float/next_float.rb,
lib/backports/2.2.0/float/prev_float.rb
Constant Summary collapse
- INFINITY =
1.0/0.0
- NAN =
0.0/0.0
Instance Method Summary collapse
Instance Method Details
#dup ⇒ Object
2 3 4 |
# File 'lib/backports/2.4.0/float/dup.rb', line 2 def dup self end |
#next_float ⇒ Object
5 6 7 8 9 |
# 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 ⇒ Object
6 7 8 9 |
# 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) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 |