Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

rational numbers, not decimal approximations


  • Please log in to reply
15 replies to this topic
Gogo
  • Guests
  • Last active:
  • Joined: --
Here is another ( better and simpler ) solution. The same idea different approach.

a := 4/3, b := 7/3

MsgBox % Fract(a+b) "     " Fract(-1000.3333333) "     " Fract(-5/6 + 3/8)

Fract( a, maxDenominator = 128, maxError = 0.00001 ) {
   Loop % maxDenominator {
      d:= A_Index, n:= Round(a*d)
      If Abs(n/d - a) <= maxError
         return n "/" d
   }
   return a
}