Java Ceil ceilDiv(int v1, int v2)

Here you can find the source of ceilDiv(int v1, int v2)

Description

ceil Div

License

Open Source License

Parameter

Parameter Description
v1 a parameter
v2 != 0

Return

ceil(v1/v2)

Declaration

public static int ceilDiv(int v1, int v2) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * OscaR 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./*from w  ww.ja  va2  s .  c o  m*/
 *   
 * OscaR 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 OscaR.
 * If not, see http://www.gnu.org/licenses/lgpl-3.0.en.html
 ******************************************************************************/

public class Main {
    /**
     * @param v1
     * @param v2 != 0
     * @return ceil(v1/v2)
     */
    public static int ceilDiv(int v1, int v2) {
        return v1 / v2
                + (((v1 % v2 != 0) && positiveProduct(v1, v2)) ? 1 : 0);
    }

    public static boolean positiveProduct(int v1, int v2) {
        return (v2 > 0 && v1 > 0) || (v1 < 0 && v2 < 0);
    }
}

Related

  1. ceil(Short a)
  2. ceil10(double a)
  3. ceil2(double d, int p)
  4. ceil2(int a, int preserveDigits)
  5. ceilDiv(int numerator, int denominator)
  6. ceilDiv(long a, long b)
  7. ceilDivide(long a, long b)
  8. ceilDivision(int value, int divisor)
  9. ceiling(double d)