Java Integer Mod modulo(int x, int m)

Here you can find the source of modulo(int x, int m)

Description

modulo

License

Open Source License

Declaration

public static final int modulo(int x, int m) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static final int modulo(int x, int m) {
        azzert(m > 0, "m must be > 0");
        int y = x % m;
        if (y < 0) {
            y += m;/*  w  ww  .  ja  v a 2  s .com*/
        }
        return y;
    }

    public static void azzert(boolean expr) {
        if (!expr) {
            throw new AssertionError();
        }
    }

    public static void azzert(boolean expr, String message) {
        if (!expr) {
            throw new AssertionError(message);
        }
    }

    public static void azzert(boolean expr, Throwable t) {
        if (!expr) {
            throw new AssertionError(t);
        }
    }
}

Related

  1. modularInvert(int num, int modulus)
  2. modulateCircularIndex(int index, int seqLength)
  3. modulo(int a, int b)
  4. modulo(int a, int b)
  5. modulo(int dividend, int divisor)
  6. modulo(int x, int mod)
  7. modulo(int x, int y)
  8. moduloPositive(final int value, final int size)
  9. moduloPowerOfTwo(final int x, final int powerOfTwoY)