I've inspected the code of .round(float a)
static method of the java.lang.Math
class and I see that it's using binary shifting operations to conduct the rounding. It's probably well optimized and fast, but I wonder on how does it compare to the standart integer casting conversion (int) a
. Assuming I have such operation:
float x = 1.8F;
int a = (int) x; // a = 1
int b = Math.round(x); // b = 2
As you can see, b
is more accurate rounding and I would prefer it, however in terms of performance is it significantly slower (if at all), than the casting? Assummıng I have >10,000 operations per second.