Java tutorial
//package com.java2s; public class Main { public static double smallestAngularDifferenceDegrees(double firstAngleDeg, double secondAngleDeg) { double d = ((firstAngleDeg - secondAngleDeg) * 3.141592653589793d) / 180.0d; return (Math.atan2(Math.sin(d), Math.cos(d)) * 180.0d) / 3.141592653589793d; } }