mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-01 01:17:40 +00:00
Added SDL_modf() and SDL_modff()
This function is useful for accumulating relative mouse motion if you want to only handle whole pixel movement. e.g. static float dx_frac, dy_frac; float dx, dy; /* Accumulate new motion with previous sub-pixel motion */ dx = event.motion.xrel + dx_frac; dy = event.motion.yrel + dy_frac; /* Split the integral and fractional motion, dx and dy will contain whole pixel deltas */ dx_frac = SDL_modff(dx, &dx); dy_frac = SDL_modff(dy, &dy); if (dx != 0.0f || dy != 0.0f) { ... }
This commit is contained in:
parent
ead4f122e4
commit
7f23d71b6a
20 changed files with 149 additions and 7 deletions
|
@ -1272,6 +1272,24 @@ log10_regularCases(void *args)
|
|||
return helper_dtod_inexact("Log10", SDL_log10, regular_cases, SDL_arraysize(regular_cases));
|
||||
}
|
||||
|
||||
/* SDL_modf tests functions */
|
||||
|
||||
static int
|
||||
modf_baseCases(void *args)
|
||||
{
|
||||
double fractional, integral;
|
||||
|
||||
fractional = SDL_modf(1.25, &integral);
|
||||
SDLTest_AssertCheck(integral == 1.0,
|
||||
"modf(%f), expected integral %f, got %f",
|
||||
1.25, 1.0, integral);
|
||||
SDLTest_AssertCheck(fractional == 0.25,
|
||||
"modf(%f), expected fractional %f, got %f",
|
||||
1.25, 0.25, fractional);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* SDL_pow tests functions */
|
||||
|
||||
/* Tests with positive and negative infinities as exponents */
|
||||
|
@ -3004,6 +3022,13 @@ static const SDLTest_TestCaseReference log10TestRegular = {
|
|||
"Checks a set of regular values", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* SDL_modf test cases */
|
||||
|
||||
static const SDLTest_TestCaseReference modfTestBase = {
|
||||
(SDLTest_TestCaseFp)modf_baseCases, "modf_baseCases",
|
||||
"Checks the base cases", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* SDL_pow test cases */
|
||||
|
||||
static const SDLTest_TestCaseReference powTestExpInf1 = {
|
||||
|
@ -3315,6 +3340,8 @@ static const SDLTest_TestCaseReference *mathTests[] = {
|
|||
&log10TestLimit, &log10TestNan,
|
||||
&log10TestBase, &log10TestRegular,
|
||||
|
||||
&modfTestBase,
|
||||
|
||||
&powTestExpInf1, &powTestExpInf2, &powTestExpInf3,
|
||||
&powTestBaseInf1, &powTestBaseInf2,
|
||||
&powTestNan1, &powTestNan2, &powTestNan3, &powTestNan4,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue