Java Float Number Mod mod(float dividend, float quotient)

Here you can find the source of mod(float dividend, float quotient)

Description

Computes the modulo relationship.

License

Open Source License

Parameter

Parameter Description
dividend number to divide
quotient number to divide by

Return

the number r with the smallest absolute value such that sign(r) == sign(quotient) and there exists an integer k such that k * quotient + r = dividend

Declaration


static float mod(float dividend, float quotient) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  ww w. j a va2s  .  c o  m
     * Computes the modulo relationship.  This is not the same as
     * Java's remainder (%) operation, which always returns a
     * value with the same sign as the dividend or 0.
     *
     * @param dividend number to divide
     * @param quotient number to divide by
     * @return the number r with the smallest absolute value such
     *         that sign(r) == sign(quotient) and there exists an
     *         integer k such that k * quotient + r = dividend
     */
    //VisibleForTesting
    static float mod(float dividend, float quotient) {
        float result = dividend % quotient;
        if (result == 0 || Math.signum(dividend) == Math.signum(quotient)) {
            return result;
        } else {
            return result + quotient;
        }
    }
}

Related

  1. mod(final float a, final float b)
  2. mod(final float a, final float mod)
  3. mod(float a, float b)
  4. mod(float a, float b)
  5. mod(float a, float b)
  6. mod2(float value)
  7. module(float[] vector)
  8. modulusSq(float[][] a)