Java Float Number Mod mod(float a, float b)

Here you can find the source of mod(float a, float b)

Description

Calculates a mod b in a way that respects negative values (for example, mod(-1, 5) == 4 , rather than -1 ).

License

Apache License

Parameter

Parameter Description
a the dividend
b the divisor

Return

a mod b

Declaration

public static float mod(float a, float b) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from  w  w w  .j a  va  2  s.co m*/
     * Calculates {@code a mod b} in a way that respects negative values (for example,
     * {@code mod(-1, 5) == 4}, rather than {@code -1}).
     *
     * @param a the dividend
     * @param b the divisor
     * @return {@code a mod b}
     */
    public static int mod(int a, int b) {
        return (a % b + b) % b;
    }

    /**
     * Calculates {@code a mod b} in a way that respects negative values (for example,
     * {@code mod(-1, 5) == 4}, rather than {@code -1}).
     *
     * @param a the dividend
     * @param b the divisor
     * @return {@code a mod b}
     */
    public static float mod(float a, float b) {
        return (a % b + b) % b;
    }
}

Related

  1. fmodf(Float float1, float float2)
  2. fmodulo(double v1, double v2)
  3. mod(final float a, final float b)
  4. mod(final float a, final float mod)
  5. mod(float a, float b)
  6. mod(float a, float b)
  7. mod(float dividend, float quotient)
  8. mod2(float value)
  9. module(float[] vector)