Skip to content
instance method

Float#divmod

(::Integer | ::Float | ::Rational) -> [ ::Integer, ::Float ]
(::Numeric) -> [ ::Numeric, ::Numeric ]
divmod(other) → array

Returns a 2-element array [q, r], where

Example
q = (self/other).floor      # Quotient
r = self % other            # Remainder

Examples:

Example
11.0.divmod(4)              # => [2, 3.0]
11.0.divmod(-4)             # => [-3, -1.0]
-11.0.divmod(4)             # => [-3, 1.0]
-11.0.divmod(-4)            # => [2, -3.0]

12.0.divmod(4)              # => [3, 0.0]
12.0.divmod(-4)             # => [-3, 0.0]
-12.0.divmod(4)             # => [-3, -0.0]
-12.0.divmod(-4)            # => [3, -0.0]

13.0.divmod(4.0)            # => [3, 1.0]
13.0.divmod(Rational(4, 1)) # => [3, 1.0]
See also #denominator #eql? #coerce #fdiv also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0