I'm looking for the efficient way of replacing approximate values (ushort[100]) for their target values.
There are two target values (ushort x, 2x), each value in the ushort[] approximates one of these two.
I'm looking for the efficient way of replacing approximate values (ushort[100]) for their target values.
There are two target values (ushort x, 2x), each value in the ushort[] approximates one of these two.
You could always just define a distance metric that allows you to assigns each of the approximate values to the expected values, considering those to be "bins", as in a histogram. Processing the values then means replacing the approximate value with the known value that has the smallest distance to that value.
var a = target1 > words[i] ? target1 - words[i] : words[i] - target1;
var b = target2 > words[i] ? target2 - words[i] : words[i] - target2;
(OR)
var as = target1 - words[i];
var bs = target2 - words[i];
a = as + (as >> 31) ^ (as >> 31);
b = bs + (bs >> 31) ^ (bs >> 31);
if (a < b)
normalized[i] = target1;
else
normalized[i] = target2;