Here you can find the source of mod(double x, double y)
public static double mod(double x, double y)
//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); } } }