mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-09 15:30:41 +00:00
round utility functions
add mRoundF to return nearest floating value to stepsize
This commit is contained in:
parent
f0e7a27c16
commit
f7ed077d82
4 changed files with 27 additions and 24 deletions
|
|
@ -217,7 +217,22 @@ inline F32 mRound(const F32 val, const S32 n)
|
|||
S32 place = (S32) pow(10.0f, n);
|
||||
|
||||
return mFloor((val*place)+0.5)/place;
|
||||
}
|
||||
}
|
||||
|
||||
inline F32 mRoundF(const F32 val, const F32 step)
|
||||
{
|
||||
if (step == 0.0f)
|
||||
return val;
|
||||
|
||||
F32 a = mFmod(val, step);
|
||||
|
||||
F32 temp = val;
|
||||
|
||||
if (mFabs(a) > (step / 2))
|
||||
val < 0.0f ? temp -= step : temp += step;
|
||||
|
||||
return(temp - a);
|
||||
}
|
||||
|
||||
inline S32 mAbs(const S32 val)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue