title: How can I turn a floating point number into the closest fraction represented by a byte numerator and denominator?
body: <p>How can I write an algorithm that given a floating point number, and attempts to represent is as accurately as possible using a numerator and a denominator, both restricted to the range of a Java byte?</p>
  
  <p>The reason for this is that an I2C device wants a numerator and denominator, while it would make sense to give it a float.</p>
  
  <p>For example, <code>3.1415926535...</code> would result in <code>245/78</code>, rather than <code>314/100</code> or <code>22/7</code>.</p>
  
  <p>In terms of efficiency, this would be called around three times at the start of the program, but after that not at all. So a slow algorithm isn't <em>too</em> bad.</p>