round double to integer (inline-assembler)
Hey,
The shortest I guess would be:
int __fastcall MathLib::Round(const double &dbl)
{
int x;
__asm
{
fld qword ptr [dbl]
fistp [x]
}
return x;
}
But you should __inline it if that's not done automatically for best speeds.
But you might want to read Agner Fog's text on this subject:
http://www.agner.org/assem/pentopth.zip
Check out chapter 27.5.
Also, if you're working on large arrays of doubles/ints at a time, you might
want to do the whole array at once using SSE code. But you should get more
familiar with ASM first I think.
Hope this helps,
/Nico
|