Hi,
How do I use the ROUND_ instruction to do a round-to-nearest of an unsigned integer to a float? Should I do ROUND first and then UTOF or viceversa?
Thank you.
Hi Rod,
If your GPU has double-precision support, you can first convert your int to double (no rounding involved), then convert it to the nearest float using d2f.
Unfortunately, there is no int-to-double conversion, but you can emulate it using a subtraction.
Here is some pseudo-code to do this. If you cannot use double-precision, the solution is more involved...
// assumes twop53.yx = double(2**53) mov I.y, twop53.y mov I.x, int_to_convert // force exponent 53 dsub tmp, I, twop53 // normalize (subtract 2^53) d2f dest, tmp // convert to float, round-to-nearest even
Micah,
I am working at the CAL level.
I did that and I found the IL doesn't use any of the ROUND_* instructions. Instead it uses a macro with some FFB's and CMOV's. Why doesn't it use the ROUND_* instructions?
Thank you.