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

Apache License

Declaration

public static int floorDiv(int dividend, int divisor) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//  w  w w .  j  a v a 2 s.  c  om
     * Computes the floored division {@code dividend/divisor} which is useful when dividing
     * potentially negative numbers into bins.
     *
     * <p> For example, the following numbers {@code 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) {
        boolean numpos = dividend >= 0, denpos = divisor >= 0;
        if (numpos == denpos)
            return dividend / divisor;
        return denpos ? (dividend - divisor + 1) / divisor : (dividend - divisor - 1) / divisor;
    }
}

Related

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