title: Java float to double - upper and lower bounds?
body: <p>As most here will know, double -> float incurs a loss in precision. This means, multiple double values may be mapped to the same float value.
  But how do I go the other way? Given a normal (I'm not caring about the extreme cases) float, how do I find the upper and lower value of double precision that are still mapped to the same float?</p>
  
  <p>Or, to speak in code:</p>
  
  <pre><code>function boolean testInterval(float lowF, float highF, double queryD) {
      float queryF = (float) queryD;
      return (lowF &lt;= queryF) &amp;&amp; (queryF &lt;= highF);
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>function boolean testInterval(float lowF, float highF, double queryD) {
      double lowD = (double) lowF;
      double highD = (double) highF;
      return (lowD &lt;= queryD) &amp;&amp; (queryD &lt;= highD);
  }
  </code></pre>
  
  <p>do not always give the same result. I'm looking for two functions float-> double to make the second function return the same result at the first.</p>
  
  <p>This could work, but it looks like a hack and not the proper solution to me.</p>
  
  <pre><code>function boolean testIntervalHack(float lowF, float highF, double queryD) {
      double lowD = (double) lowF - Float.MIN_VALUE;
      double highD = (double) highF + Float.MIN_VALUE;
      return (lowD &lt;= queryD) &amp;&amp; (queryD &lt;= highD);
  }
  </code></pre>