convert a positive float array to an unsigned short array with rounding in C++
<p>I have a positive float array and would like to convert this array to an unsigned short array with rounding. How can I do that in an efficient way? Here is an example:</p>

<pre><code>float floatArr[] = {1.2, 1.8, 2.1, 2.5, 3.2};
unsigned short usArr[5];
// I could do this
std::copy(floatArr, 5, usArr);
</code></pre>

<p>However, it will only do the casting, since it basically copies the first two bytes. So the result is <code>usArr[] = {1, 1, 2, 2, 3}</code>. My question is how can I convert this float array with rounding, instead of casting, to be <code>usArr[] = {1, 2, 2, 3, 3}</code>? Thank you and I would appreciate any help!</p>