Java Float Number Divide Divide_S(float quotient, float divisor)

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

Description

(Divide_Safe) Performs a divide using 'safe' versions of the quotient and divisor and returns the value.

License

Open Source License

Declaration

public static float Divide_S(float quotient, float divisor) 

Method Source Code

//package com.java2s;
/*//from www  .  ja  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)
     * 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_SL(final float quotient, final float divisor)