Java Double Number mod mod(double x, double y)

Here you can find the source of mod(double x, double y)

Description

Performs 'x modulo y' (not to be confused with the remainder operator '%', which behaves differently when x is negative).

License

LGPL

Declaration

public static double mod(double x, double y) 

Method Source Code

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

public class Main {
    public static int mod(int x, int y) {
        if (x >= 0) {
            return x % y;
        } else {//  w ww .j  a  v  a  2s . c o  m
            int tmp = -x % y; // make x positive before calc'ing remainder
            return (tmp == 0) ? tmp : (y - tmp);
        }
    }

    /**
     * Performs 'x modulo y' (not to be confused with the remainder operator '%',
     * which behaves differently when x is negative).
     */
    public static double mod(double x, double y) {
        if (x >= 0) {
            return x % y;
        } else {
            double tmp = -x % y; // make x positive before calc'ing remainder
            return (tmp == 0) ? tmp : (y - tmp);
        }
    }
}

Related

  1. mod(double m, double n)
  2. mod(double n, double d)
  3. mod(double number, double mod)
  4. mod(double value, double mod)
  5. mod(double x, double m)
  6. mod(double x, double y)
  7. mod(double x, double y)
  8. mod(final double a, final double b)
  9. mod2pi(double vin)