File: next_float.rb

package info (click to toggle)
ruby-backports 3.25.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,912 kB
  • sloc: ruby: 11,757; makefile: 6
file content (11 lines) | stat: -rw-r--r-- 320 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
unless Float.method_defined? :next_float
  require 'backports/tools/float_integer_conversion'

  class Float
    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
  end
end