Java Float Number Divide Divide_SL(final float quotient, final float divisor)

Here you can find the source of Divide_SL(final float quotient, final float divisor)

Description

(Divide_Safe_Limit) Performs a divide using 'safe' versions of the quotient and divisor, and returns the value as a 'limited' number.

License

Open Source License

Declaration

public static float Divide_SL(final float quotient, final float divisor) 

Method Source Code

//package com.java2s;
/*//from w  ww .  j  a  v a  2  s.c o m
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 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
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

public class Main {
    /**
     * (Divide_Safe_Limit)
     * Performs a divide using 'safe' versions of the quotient and divisor, and returns the value as a 'limited' number. (0.0F-1.0F)
     */
    public static float Divide_SL(final float quotient, final float divisor) {
        return Limit(Divide_S(quotient, divisor));
    }

    /**
     * @return Returns a limited version of the number. (On or between min and max)
     */
    public static float Limit(final float value, final float min,
            final float max) {
        return Math.min(Math.max(value, min), max);
    }

    /**
     * @return Returns a limited version of the number. (On or between 0.0F and 1.0F)
     */
    public static float Limit(final float value) {
        return Limit(value, 0.0F, 1.0F);
    }

    /**
     * (Divide_Safe)
     * Performs a divide using 'safe' versions of the quotient and divisor and returns the value.
     */
    public static float Divide_S(float quotient, float divisor) {
        quotient = MNZ(quotient);
        divisor = MNZ(divisor);
        return quotient / divisor;
    }

    /**
     * (MakeNonZero)
     * 
     * @param value
     *            - The number to make non-zero
     * @return - Returns 0.001F if the number is 0.0F, otherwise returns the number itself
     */
    public static float MNZ(float value) {
        if (value == 0.0F)
            value = 0.001F;
        return value;
    }
}

Related

  1. div(final float a, final float b)
  2. div(float f1, float f2)
  3. divide(final float dividend, final float divisor)
  4. Divide_S(float quotient, float divisor)