Java Integer Mod modulus(int value, int truncate, boolean flag)

Here you can find the source of modulus(int value, int truncate, boolean flag)

Description

modulus

License

Apache License

Parameter

Parameter Description
value a parameter
truncate a parameter

Return

modulus value equivalent to python modulus

Declaration

public static int modulus(int value, int truncate, boolean flag) 

Method Source Code

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

public class Main {
    /**/* w  w  w .  j  av a2 s.c o  m*/
     * 
     * @param value
     * @param truncate
     * @return modulus value equivalent to python modulus
     */
    public static double modulus(double value, double truncate) {
        double newValue = value % truncate;
        // to get the same result as python (%) gives
        if (newValue < 0) {
            newValue += truncate;
        }

        return newValue;
    }

    /**
     * 
     * @param value
     * @param truncate
     * @return modulus value equivalent to python modulus
     */
    public static int modulus(int value, int truncate, boolean flag) {
        int newValue = value % truncate;
        // to get the same result as python (%) gives
        while (newValue < 0) {
            newValue += truncate;
        }

        return newValue;
    }
}

Related

  1. modulo(int x, int y)
  2. moduloPositive(final int value, final int size)
  3. moduloPowerOfTwo(final int x, final int powerOfTwoY)
  4. modulus(int a, int b)
  5. modulus(int a, int b)
  6. modulus(int[] array)