mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-08 19:06:26 +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:
@@ -859,6 +859,8 @@ SDL3_0.0.0 {
|
||||
SDL_wcsncasecmp;
|
||||
SDL_wcsncmp;
|
||||
SDL_wcsstr;
|
||||
SDL_modf;
|
||||
SDL_modff;
|
||||
# extra symbols go here (don't modify this line)
|
||||
local: *;
|
||||
};
|
||||
|
@@ -887,3 +887,5 @@
|
||||
#define SDL_wcsstr SDL_wcsstr_REAL
|
||||
|
||||
/* New API symbols are added at the end */
|
||||
#define SDL_modf SDL_modf_REAL
|
||||
#define SDL_modff SDL_modff_REAL
|
||||
|
@@ -932,3 +932,5 @@ SDL_DYNAPI_PROC(int,SDL_wcsncmp,(const wchar_t *a, const wchar_t *b, size_t c),(
|
||||
SDL_DYNAPI_PROC(wchar_t*,SDL_wcsstr,(const wchar_t *a, const wchar_t *b),(a,b),return)
|
||||
|
||||
/* New API symbols are added at the end */
|
||||
SDL_DYNAPI_PROC(double,SDL_modf,(double a, double *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(float,SDL_modff,(float a, float *b),(a,b),return)
|
||||
|
@@ -27,16 +27,17 @@
|
||||
/* Math routines from uClibc: http://www.uclibc.org */
|
||||
|
||||
double SDL_uclibc_atan(double x);
|
||||
double SDL_uclibc_atan2(double y, double x);
|
||||
double SDL_uclibc_copysign(double x, double y);
|
||||
double SDL_uclibc_cos(double x);
|
||||
double SDL_uclibc_atan2(double y, double x);
|
||||
double SDL_uclibc_copysign(double x, double y);
|
||||
double SDL_uclibc_cos(double x);
|
||||
double SDL_uclibc_exp(double x);
|
||||
double SDL_uclibc_fabs(double x);
|
||||
double SDL_uclibc_fabs(double x);
|
||||
double SDL_uclibc_floor(double x);
|
||||
double SDL_uclibc_fmod(double x, double y);
|
||||
double SDL_uclibc_log(double x);
|
||||
double SDL_uclibc_log10(double x);
|
||||
double SDL_uclibc_pow(double x, double y);
|
||||
double SDL_uclibc_modf(double x, double *y);
|
||||
double SDL_uclibc_pow(double x, double y);
|
||||
double SDL_uclibc_scalbn(double x, int n);
|
||||
double SDL_uclibc_sin(double x);
|
||||
double SDL_uclibc_sqrt(double x);
|
||||
|
@@ -40,6 +40,7 @@ typedef unsigned int u_int32_t;
|
||||
#define __ieee754_fmod SDL_uclibc_fmod
|
||||
#define __ieee754_log SDL_uclibc_log
|
||||
#define __ieee754_log10 SDL_uclibc_log10
|
||||
#define modf SDL_uclibc_modf
|
||||
#define __ieee754_pow SDL_uclibc_pow
|
||||
#define scalbln SDL_uclibc_scalbln
|
||||
#define scalbn SDL_uclibc_scalbn
|
||||
|
68
src/libm/s_modf.c
Normal file
68
src/libm/s_modf.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "SDL_internal.h"
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
* modf(double x, double *iptr)
|
||||
* return fraction part of x, and return x's integral part in *iptr.
|
||||
* Method:
|
||||
* Bit twiddling.
|
||||
*
|
||||
* Exception:
|
||||
* No exception.
|
||||
*/
|
||||
|
||||
#include "math_libm.h"
|
||||
#include "math_private.h"
|
||||
|
||||
static const double one = 1.0;
|
||||
|
||||
double modf(double x, double *iptr)
|
||||
{
|
||||
int32_t i0,i1,_j0;
|
||||
u_int32_t i;
|
||||
EXTRACT_WORDS(i0,i1,x);
|
||||
_j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */
|
||||
if(_j0<20) { /* integer part in high x */
|
||||
if(_j0<0) { /* |x|<1 */
|
||||
INSERT_WORDS(*iptr,i0&0x80000000,0); /* *iptr = +-0 */
|
||||
return x;
|
||||
} else {
|
||||
i = (0x000fffff)>>_j0;
|
||||
if(((i0&i)|i1)==0) { /* x is integral */
|
||||
*iptr = x;
|
||||
INSERT_WORDS(x,i0&0x80000000,0); /* return +-0 */
|
||||
return x;
|
||||
} else {
|
||||
INSERT_WORDS(*iptr,i0&(~i),0);
|
||||
return x - *iptr;
|
||||
}
|
||||
}
|
||||
} else if (_j0>51) { /* no fraction part */
|
||||
*iptr = x*one;
|
||||
/* We must handle NaNs separately. */
|
||||
if (_j0 == 0x400 && ((i0 & 0xfffff) | i1))
|
||||
return x*one;
|
||||
INSERT_WORDS(x,i0&0x80000000,0); /* return +-0 */
|
||||
return x;
|
||||
} else { /* fraction part in low x */
|
||||
i = ((u_int32_t)(0xffffffff))>>(_j0-20);
|
||||
if((i1&i)==0) { /* x is integral */
|
||||
*iptr = x;
|
||||
INSERT_WORDS(x,i0&0x80000000,0); /* return +-0 */
|
||||
return x;
|
||||
} else {
|
||||
INSERT_WORDS(*iptr,i0,i1&(~i));
|
||||
return x - *iptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
libm_hidden_def(modf)
|
@@ -322,6 +322,28 @@ float SDL_log10f(float x)
|
||||
#endif
|
||||
}
|
||||
|
||||
double
|
||||
SDL_modf(double x, double *y)
|
||||
{
|
||||
#if defined(HAVE_MODF)
|
||||
return modf(x, y);
|
||||
#else
|
||||
return SDL_uclibc_modf(x, y);
|
||||
#endif
|
||||
}
|
||||
|
||||
float SDL_modff(float x, float *y)
|
||||
{
|
||||
#if defined(HAVE_MODFF)
|
||||
return modff(x, y);
|
||||
#else
|
||||
double double_result, double_y;
|
||||
double_result = SDL_modf((double)x, &double_y);
|
||||
*y = (float)double_y;
|
||||
return (float)double_result;
|
||||
#endif
|
||||
}
|
||||
|
||||
double
|
||||
SDL_pow(double x, double y)
|
||||
{
|
||||
|
Reference in New Issue
Block a user