我正在寻找替换目标值的近似值(ushort [100])的有效方法。
有两个目标值(ushort x,2x),ushort []中的每个值近似于这两个中的一个。
答案 0 :(得分:1)
答案 1 :(得分:1)
您可以随时定义一个距离度量,允许您将每个近似值分配给预期值,将其视为“bins”,如直方图中所示。然后处理这些值意味着用距离该值最小的已知值替换近似值。
答案 2 :(得分:0)
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;