title: Using FloatMath or Math and a cast?
body: <p>In the latest update of the Android API the <a href="http://developer.android.com/reference/android/util/FloatMath.html"><code>FloatMath</code></a> is marked with the following lint-warning:</p>
  
  <blockquote>
    <p>In older versions of Android, using android.util.FloatMath was
    recommended for performance reasons when operating on floats. However,
    on modern hardware doubles are just as fast as float (though they take
    more memory), and in recent versions of Android, FloatMath is actually
    slower than using java.lang.Math due to the way the JIT optimizes
    java.lang.Math. Therefore, you should use Math instead of FloatMath if
    you are only targeting Froyo and above.</p>
  </blockquote>
  
  <p>It is also mentioned <a href="http://developer.android.com/training/articles/perf-tips.html#AvoidFloat">here</a> that double and float are equal in speed on recent hardware.</p>
  
  <p>I am using some trigonometric math in an application I am currently working on (targeted Froyo and above), but high precision is not needed, so I have been using floats and <code>FloatMath</code> so far, and there is no need whatsoever to switch to doubles.<br>
  However, the "use <code>Math</code> over <code>FloatMath</code>"-recommendation does not say which one to use if float is the desired result.</p>
  
  <p>So, in short; which one is preferable?</p>
  
  <pre><code>float foo = FloatMath.sin(bar);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>float foo = (float) Math.sin(bar);
  </code></pre>
  
  <p><em>On a side note, I only have a Froyo-device, so I can't really do any proper benchmarking on my own.</em></p>
  
  <p><strong>As of API level 22 the FloatMath-class has been deprecated in favor of the regular Math-class.</strong></p>