Java Integer Mod mod(int a, int n)

Here you can find the source of mod(int a, int n)

Description

"correct" mod function.

License

Open Source License

Declaration

public static int mod(int a, int n) 

Method Source Code

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

public class Main {
    /** "correct" mod function. */
    public static int mod(int a, int n) {
        if (n < 0)
            return mod(a, -n);
        if (n == 0)
            return a % n; // crash and burn
        int rtn = a % n;
        while (rtn < 0)
            rtn += n;//from  w  w w  . j av  a 2 s.  c o  m
        return rtn;
    }
}

Related

  1. mod(int a, int b)
  2. Mod(int a, int b)
  3. mod(int a, int b)
  4. mod(int a, int b)
  5. mod(int a, int n)
  6. mod(int divisor, int dividend)
  7. mod(int hash, int size)
  8. mod(int i, int n)
  9. mod(int num, int div)