using System; // ReSharper disable CompareOfFloatsByEqualityOperator namespace HeuristicLab.Problems.ProgramSynthesis { public static class MathExtensions { public static long AbsoluteDiff(this long a, long b) { var diff = a - b; return diff == long.MinValue ? long.MaxValue : Math.Abs(diff); } public static long AbsoluteDiff(this int a, long b) { return AbsoluteDiff((long)a, b); } public static int AbsoluteDiff(this int a, int b) { var diff = a - b; return diff == int.MinValue ? int.MaxValue : Math.Abs(diff); } public static double AbsoluteDiff(this double a, double b) { var diff = a - b; return diff == double.MinValue || double.IsNaN(diff) || double.IsInfinity(diff) ? double.MaxValue : Math.Abs(diff); } public static int AbsoluteDiff(this char a, char b) { var diff = a - b; return diff == int.MinValue ? int.MaxValue : Math.Abs(diff); } } }