Java tutorial
//package com.java2s; public class Main { public static float clampAngle(float angle) { float res = angle % (float) (Math.PI * 2); if (res < 0) { res += Math.PI * 2; } return res; } }