Here you can find the source of ceil_divide(float left, float right)
Parameter | Description |
---|---|
left | the left float value |
right | the right float value |
public static int ceil_divide(float left, float right)
//package com.java2s; /**/* www. j a va 2s. c om*/ * AADL-Utils * * Copyright ? 2012 TELECOM ParisTech and CNRS * * TELECOM ParisTech/LTCI * * Authors: see AUTHORS * * This program is free software: you can redistribute it and/or modify * it under the terms of the Eclipse Public License as published by Eclipse, * either version 1.0 of the License, or (at your option) any later version. * This program 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 * Eclipse Public License for more details. * You should have received a copy of the Eclipse Public License * along with this program. If not, see * http://www.eclipse.org/org/documents/epl-v10.php */ import java.math.BigDecimal; public class Main { /** * Divides the given left float value by the given right float value and * returns the smallest integer value of division result that is not less than * the result. * * @param left the left float value * @param right the right float value * @return the smallest integer value of division result that is not less than * the result */ public static int ceil_divide(float left, float right) { float resF = divide(left, right); if (((int) resF) != resF) { return 1 + (int) resF; } else { return (int) resF; } } /** * Divides the given left float value by the given right float value. * * @param left the left float value * @param right the right float value * @return the division result */ public static float divide(float left, float right) { BigDecimal iLeft = new BigDecimal(left + ""); BigDecimal iRight = new BigDecimal(right + ""); try { return iLeft.divide(iRight).floatValue(); } catch (Exception e) { return iLeft.divide(iRight, BigDecimal.ROUND_HALF_DOWN).floatValue(); } } }