Java floor floorDivide(int value, int divisor)

Here you can find the source of floorDivide(int value, int divisor)

Description

Returns the largest lower limit of quotient.

License

Open Source License

Parameter

Parameter Description
value numerator
divisor divisor

Return

quotient as result of division

Declaration


public static int floorDivide(int value, int divisor) 

Method Source Code

//package com.java2s;
/*//from  www  .  j a v  a2 s .c om
 * -----------------------------------------------------------------------
 * Copyright ? 2013-2014 Meno Hochschild, <http://www.menodata.de/>
 * -----------------------------------------------------------------------
 * This file (MathUtils.java) is part of project Time4J.
 *
 * Time4J is free software: You can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * Time4J is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Time4J. If not, see <http://www.gnu.org/licenses/>.
 * -----------------------------------------------------------------------
 */

public class Main {
    /**
     * <p>Returns the largest lower limit of quotient. </p>
     *
     * <p>Examples: </p>
     *
     * <ul>
     *  <li>{@code floorDivide(2, 2) == 1}</li>
     *  <li>{@code floorDivide(1, 2) == 0}</li>
     *  <li>{@code floorDivide(0, 2) == 0}</li>
     *  <li>{@code floorDivide(-1, 2) == -1}</li>
     *  <li>{@code floorDivide(-2, 2) == -1}</li>
     *  <li>{@code floorDivide(-3, 2) == -2}</li>
     * </ul>
     *
     * @param   value       numerator
     * @param   divisor     divisor
     * @return  quotient as result of division
     */
    /*[deutsch]
     * <p>Liefert die gr&ouml;&szlig;te untere Schranke des Quotienten. </p>
     *
     * <p>Beispiele: </p>
     *
     * <ul>
     *  <li>{@code floorDivide(2, 2) == 1}</li>
     *  <li>{@code floorDivide(1, 2) == 0}</li>
     *  <li>{@code floorDivide(0, 2) == 0}</li>
     *  <li>{@code floorDivide(-1, 2) == -1}</li>
     *  <li>{@code floorDivide(-2, 2) == -1}</li>
     *  <li>{@code floorDivide(-3, 2) == -2}</li>
     * </ul>
     *
     * @param   value       numerator
     * @param   divisor     divisor
     * @return  quotient as result of division
     */
    public static int floorDivide(int value, int divisor) {

        if (value >= 0) {
            return (value / divisor);
        } else {
            return ((value + 1) / divisor) - 1;
        }

    }

    /**
     * <p>See {@link #floorDivide(int, int)}. </p>
     *
     * @param   value       numerator
     * @param   divisor     divisor
     * @return  quotient as result of division
     */
    /*[deutsch]
     * <p>Siehe {@link #floorDivide(int, int)}. </p>
     *
     * @param   value       numerator
     * @param   divisor     divisor
     * @return  quotient as result of division
     */
    public static long floorDivide(long value, int divisor) {

        if (value >= 0) {
            return (value / divisor);
        } else {
            return ((value + 1) / divisor) - 1;
        }

    }
}

Related

  1. floorDiv(int dividend, int divisor)
  2. floorDiv(int dividend, int divisor)
  3. floorDiv(int v1, int v2)
  4. floorDiv(long a, long b)
  5. floorDiv(long x, long y)
  6. floorDivide(long n, long d)
  7. floorDivide(long numerator, long denominator)
  8. floorDivision(int i, int divisor)
  9. floorHalf(int num)