Here you can find the source of clamp_wrap(int a, int x, int y)
public static int clamp_wrap(int a, int x, int y)
//package com.java2s; public class Main { /**//from w w w . j a va2s . co m * Returns the given double clamped between the two values (wraps around if out of range). */ public static int clamp_wrap(int a, int x, int y) { return a < x ? y - (x - a) % (y - x) : a > y ? x + (a - y) % (y - x) : a; } /** * Returns the given double clamped between the two values (wraps around if out of range). */ public static double clamp_wrap(double a, double x, double y) { return a < x ? y - Math.IEEEremainder(x - a, y - x) : a > y ? x + Math.IEEEremainder(a - y, y - x) : a; } }