public static KeyValuePair <int, int> RationalRatio(double x) { for (int val = 2; val < RATIO_MAX; val++) { // Do we acquire an integer? if (Utilities.CompareValues(x * val, Math.Floor(x * val))) { int gcd = Utilities.GCD(val, (int)Math.Round(x * val)); return(x < 1 ? new KeyValuePair <int, int>(val / gcd, (int)Math.Round(x * val) / gcd) : new KeyValuePair <int, int>((int)Math.Round(x * val) / gcd, val / gcd)); } } return(new KeyValuePair <int, int>(-1, -1)); }