Java floor floorDiv(int dividend, int divisor)

Here you can find the source of floorDiv(int dividend, int divisor)

Description

Computes the floored division dividend/divisor which is useful when dividing potentially negative numbers into bins.

License

Open Source License

Declaration

public static int floorDiv(int dividend, int divisor) 

Method Source Code

//package com.java2s;
// under the terms of the GNU Lesser General Public License as published

public class Main {
    /**//from   w  ww  .  java  2  s  . co m
     * Computes the floored division <code>dividend/divisor</code> which
     * is useful when dividing potentially negative numbers into bins. For
     * positive numbers, it is the same as normal division, for negative
     * numbers it returns <code>(dividend - divisor + 1) / divisor</code>.
     *
     * <p> For example, the following numbers floorDiv 10 are:
     * <pre>
     * -15 -10 -8 -2 0 2 8 10 15
     *  -2  -1 -1 -1 0 0 0  1  1
     * </pre>
     */
    public static int floorDiv(int dividend, int divisor) {
        return ((dividend >= 0) ? dividend : (dividend - divisor + 1)) / divisor;
    }
}

Related

  1. floorData(float[] data, float floor)
  2. floorDay(long milli)
  3. floorDiv(final int x, final int y)
  4. floorDiv(int dividend, int divisor)
  5. floorDiv(int dividend, int divisor)
  6. floorDiv(int v1, int v2)
  7. floorDiv(long a, long b)
  8. floorDiv(long x, long y)
  9. floorDivide(int value, int divisor)