Here you can find the source of mod(double number, double mod)
public static double mod(double number, double mod)
//package com.java2s; //License from project: Open Source License public class Main { public static double mod(double number, double mod) { if (Math.abs(mod) <= Double.MIN_NORMAL) { return 0; }//from ww w . ja va 2 s . c om if (number < 0) { return mod(number + mod, mod); } else if (number >= mod) { return mod(number - mod, mod); } else { return number; } } public static int mod(int number, int mod) { if (mod <= 0) { return 0; } if (number < 0) { return mod(number + mod, mod); } else if (number >= mod) { return mod(number - mod, mod); } else { return number; } } }