I have a short to float cast in C++ that is bottlenecking my code.
The code translates from a hardware device buffer which is natively shorts, this represents the in
You could try to approximate the expression
float factor = 1.0f/value;
by an fraction numerator/denomitator
where both numerator
and denominator
are int
s. This can be done to the precision you need in your application like
int denominator = 10000;
int numerator = factor * denominator;
Then you can do your computation in integer arithmetics like
int value = source[i];
destination[i] = (value * numerator) / numerator;
You have to take care of overflows, perhaps you need to switch to long
(or even long long
on 64bit systems) for the calculation.