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: Open Source License public class Main { public static double mod(double x, double y) { if (0. == y) return x; double m = x - y * Math.floor(x / y); // handle boundary cases resulted from floating-point cut off: if (y > 0) { // modulo range: [0..y) if (m >= y) // Mod(-1e-16 , 360. ): m= 360. return 0; if (m < 0) { if (y + m == y) return 0; // just in case... else return y + m; // Mod(106.81415022205296 , _TWO_PI ): m= -1.421e-14 }//from ww w . j a v a 2s. c om } else { // modulo range: (y..0] if (m <= y) // Mod(1e-16 , -360. ): m= -360. return 0; if (m > 0) { if (y + m == y) return 0; // just in case... else return y + m; // Mod(-106.81415022205296, -_TWO_PI): m= 1.421e-14 } } return m; } }