add float_to_int() rounding function from Cockpit/hud_opts.hxx. The original

file said "(c) FlightGear Project" and "probably written by Norman Vine".
This commit is contained in:
mfranz
2006-06-16 09:29:54 +00:00
parent 52f57160aa
commit 52b8f924aa
2 changed files with 32 additions and 1 deletions

View File

@@ -2,7 +2,7 @@
* \file fastmath.cxx
* fast mathematics routines.
*
* Refferences:
* References:
*
* A Fast, Compact Approximation of the Exponential Function
* Nicol N. Schraudolph

View File

@@ -112,5 +112,36 @@ inline int fast_sgn(float f)
return 1+(((*(int*)&f)>>31)<<1);
}
/**
* Quick rounding function.
*/
#if defined(i386)
#define USE_X86_ASM
#endif
#if defined(USE_X86_ASM)
static __inline__ int float_to_int(float f)
{
int r;
__asm__ ("fistpl %0" : "=m" (r) : "t" (f) : "st");
return r;
}
#elif defined(__MSC__) && defined(__WIN32__)
static __inline int float_to_int(float f)
{
int r;
_asm {
fld f
fistp r
}
return r;
}
#else
#define float_to_int(F) ((int) ((F) < 0.0f ? (F)-0.5f : (F)+0.5f))
#endif
#endif // !_SG_FMATH_HXX