Sha256: 8f4066fa8107dce3b3e8d6b49048bba615a9d75621cde4c109e35f0fca8e28e5

Contents?: true

Size: 1.01 KB

Versions: 9

Compression:

Stored size: 1.01 KB

Contents

module Polyfill
  module V2_4
    module Float
      def ceil(ndigits = 0)
        ndigits = InternalUtils.to_int(ndigits)
        return super() if ndigits == 0

        if ndigits > 0
          place = 10**ndigits
          (self * place).ceil / place.to_f
        else
          place = 10**-ndigits
          (self / place).ceil * place
        end
      end

      def floor(ndigits = 0)
        ndigits = InternalUtils.to_int(ndigits)
        return super() if ndigits == 0

        if ndigits > 0
          place = 10**ndigits
          (self * place).floor / place.to_f
        else
          place = 10**-ndigits
          (self / place).floor * place
        end
      end

      def truncate(ndigits = 0)
        ndigits = InternalUtils.to_int(ndigits)
        return super() if ndigits == 0

        if ndigits > 0
          place = 10**ndigits
          (self * place).truncate / place.to_f
        else
          place = 10**-ndigits
          (self / place).truncate * place
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
polyfill-1.9.0 lib/polyfill/v2_4/float.rb
polyfill-1.8.0 lib/polyfill/v2_4/float.rb
polyfill-1.7.0 lib/polyfill/v2_4/float.rb
polyfill-1.6.0 lib/polyfill/v2_4/float.rb
polyfill-1.5.0 lib/polyfill/v2_4/float.rb
polyfill-1.4.0 lib/polyfill/v2_4/float.rb
polyfill-1.3.0 lib/polyfill/v2_4/float.rb
polyfill-1.2.0 lib/polyfill/v2_4/float.rb
polyfill-1.1.0 lib/polyfill/v2_4/float.rb