Fixed some warnings raised by -Wfloat-equal of GCC

See https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
This commit is contained in:
kevin2 2023-02-10 22:58:22 +01:00
parent adf31f6ec0
commit 5dbb7d59ed
11 changed files with 57 additions and 34 deletions

View file

@ -251,8 +251,31 @@ typedef uint64_t Uint64;
#define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
#endif
#ifdef DBL_EPSILON
#define SDL_DBL_EPSILON DBL_EPSILON
#else
#define SDL_DBL_EPSILON 2.220446e-16
#endif
/* @} *//* Floating-point constants */
#define SDL_FLOAT_IS_ZERO(value, epsilon) \
((value) > - (epsilon) && (value) < + (epsilon))
#define SDL_FLOAT_EQUAL(value1, value2, epsilon) \
(((value1) - (value2)) < + (epsilon) \
&& \
((value1) - (value2)) > - (epsilon))
#define SDL_FLT_IS_ZERO(value) \
SDL_FLOAT_IS_ZERO(value, SDL_FLT_EPSILON)
#define SDL_FLT_EQUAL(value1, value2) \
SDL_FLOAT_EQUAL(value1, value2, SDL_FLT_EPSILON)
#define SDL_DBL_IS_ZERO(value) \
SDL_FLOAT_IS_ZERO(value, SDL_DBL_EPSILON)
#define SDL_DBL_EQUAL(value1, value2) \
SDL_FLOAT_EQUAL(value1, value2, SDL_DBL_EPSILON)
/* Make sure we have macros for printing width-based integers.
* <stdint.h> should define these but this is not true all platforms.
* (for example win32) */

View file

@ -218,7 +218,7 @@ SDL_ResampleAudio(const int chans, const int inrate, const int outrate,
const ResampleFloatType intime = ((ResampleFloatType) srcindex) / finrate;
const ResampleFloatType innexttime = ((ResampleFloatType) (srcindex + 1)) / finrate;
const ResampleFloatType indeltatime = innexttime - intime;
const ResampleFloatType interpolation1 = (indeltatime == 0.0f) ? 1.0f : (1.0f - ((innexttime - outtime) / indeltatime));
const ResampleFloatType interpolation1 = SDL_FLT_IS_ZERO(indeltatime) ? 1.0f : (1.0f - ((innexttime - outtime) / indeltatime));
const int filterindex1 = (int) (interpolation1 * RESAMPLER_SAMPLES_PER_ZERO_CROSSING);
const ResampleFloatType interpolation2 = 1.0f - interpolation1;
const int filterindex2 = (int) (interpolation2 * RESAMPLER_SAMPLES_PER_ZERO_CROSSING);

View file

@ -671,7 +671,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
dtheta = (float)SDL_atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
dDist = (Dist - lDist);
if (lDist == 0) {dDist = 0;dtheta = 0;} /* To avoid impossible values */
if (SDL_FLT_IS_ZERO(lDist)) {dDist = 0;dtheta = 0;} /* To avoid impossible values */
/* inTouch->gestureLast[j].dDist = dDist;
inTouch->gestureLast[j].dtheta = dtheta;

View file

@ -383,7 +383,7 @@ SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int
static int
GetScaledMouseDelta(float scale, int value, float *accum)
{
if (value && scale != 1.0f) {
if (value && !SDL_FLT_EQUAL(scale, 1.0f)) {
if ((value > 0) != (*accum > 0)) {
*accum = 0.0f;
}
@ -838,7 +838,7 @@ SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, float x, float y, S
SDL_SetMouseFocus(window);
}
if (x == 0.0f && y == 0.0f) {
if (SDL_FLT_IS_ZERO(x) && SDL_FLT_IS_ZERO(y)) {
return 0;
}

View file

@ -423,7 +423,7 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, SDL_Window * window,
prel = pressure - finger->pressure;
/* Drop events that don't change state */
if (xrel == 0.0f && yrel == 0.0f && prel == 0.0f) {
if (SDL_FLT_IS_ZERO(xrel) && SDL_FLT_IS_ZERO(yrel) && SDL_FLT_IS_ZERO(prel)) {
#if 0
printf("Touch event didn't change state - dropped!\n");
#endif

View file

@ -2947,7 +2947,7 @@ int SDL_PrivateJoystickTouchpad(SDL_Joystick *joystick, int touchpad, int finger
finger_info = &touchpad_info->fingers[finger];
if (!state) {
if (x == 0.0f && y == 0.0f) {
if (SDL_FLT_IS_ZERO(x) && SDL_FLT_IS_ZERO(y)) {
x = finger_info->x;
y = finger_info->y;
}
@ -2972,7 +2972,7 @@ int SDL_PrivateJoystickTouchpad(SDL_Joystick *joystick, int touchpad, int finger
if (state == finger_info->state) {
if (!state ||
(x == finger_info->x && y == finger_info->y && pressure == finger_info->pressure)) {
(SDL_FLT_EQUAL(x, finger_info->x) && SDL_FLT_EQUAL(y, finger_info->y) && SDL_FLT_EQUAL(pressure, finger_info->pressure))) {
return 0;
}
}

View file

@ -848,7 +848,7 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
physical_h = ((float) h) * renderer->dpi_scale.y;
}
if (physical_w == 0.0f) { /* nowhere for the touch to go, avoid division by zero and put it dead center. */
if (SDL_FLT_IS_ZERO(physical_w)) { /* nowhere for the touch to go, avoid division by zero and put it dead center. */
event->tfinger.x = 0.5f;
} else {
const float normalized_viewport_x = ((float) viewport.x) / physical_w;
@ -862,7 +862,7 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
}
}
if (physical_h == 0.0f) { /* nowhere for the touch to go, avoid division by zero and put it dead center. */
if (SDL_FLT_IS_ZERO(physical_h)) { /* nowhere for the touch to go, avoid division by zero and put it dead center. */
event->tfinger.y = 0.5f;
} else {
const float normalized_viewport_y = ((float) viewport.y) / physical_h;
@ -2785,7 +2785,7 @@ SDL_RenderDrawPoints(SDL_Renderer * renderer,
}
#endif
if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
if (!SDL_FLT_EQUAL(renderer->scale.x, 1.0f) || SDL_FLT_EQUAL(renderer->scale.y, 1.0f)) {
retval = RenderDrawPointsWithRects(renderer, points, count);
} else {
fpoints = SDL_small_alloc(SDL_FPoint, count, &isstack);
@ -2858,7 +2858,7 @@ SDL_RenderDrawPointsF(SDL_Renderer * renderer,
}
#endif
if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
if (!SDL_FLT_EQUAL(renderer->scale.x, 1.0f) || !SDL_FLT_EQUAL(renderer->scale.y, 1.0f)) {
retval = RenderDrawPointsWithRectsF(renderer, points, count);
} else {
retval = QueueCmdDrawPoints(renderer, points, count);
@ -2956,7 +2956,7 @@ static int RenderDrawLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x
}
}
if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
if (!SDL_FLT_EQUAL(renderer->scale.x, 1.0f) || !SDL_FLT_EQUAL(renderer->scale.y, 1.0f)) {
retval = RenderDrawPointsWithRectsF(renderer, points, numpixels);
} else {
retval = QueueCmdDrawPoints(renderer, points, numpixels);
@ -2987,11 +2987,11 @@ RenderDrawLinesWithRectsF(SDL_Renderer * renderer,
}
for (i = 0; i < count-1; ++i) {
SDL_bool same_x = (points[i].x == points[i+1].x);
SDL_bool same_y = (points[i].y == points[i+1].y);
SDL_bool same_x = SDL_FLT_EQUAL(points[i].x, points[i+1].x);
SDL_bool same_y = SDL_FLT_EQUAL(points[i].y, points[i+1].y);
if (i == (count - 2)) {
if (!drew_line || points[i+1].x != points[0].x || points[i+1].y != points[0].y) {
if (!drew_line || !SDL_FLT_EQUAL(points[i+1].x, points[0].x) || !SDL_FLT_EQUAL(points[i+1].y, points[0].y)) {
draw_last = SDL_TRUE;
}
} else {
@ -3128,7 +3128,7 @@ SDL_RenderDrawLinesF(SDL_Renderer * renderer,
int num_indices = 0;
const int size_indices = 4;
int cur_index = -4;
const int is_looping = (points[0].x == points[count - 1].x && points[0].y == points[count - 1].y);
const int is_looping = (SDL_FLT_EQUAL(points[0].x, points[count - 1].x) && SDL_FLT_EQUAL(points[0].y, points[count - 1].y));
SDL_FPoint p; /* previous point */
p.x = p.y = 0.0f;
/* p q
@ -3173,7 +3173,7 @@ SDL_RenderDrawLinesF(SDL_Renderer * renderer,
}
/* draw segment */
if (p.y == q.y) {
if (SDL_FLT_EQUAL(p.y, q.y)) {
if (p.x < q.x) {
ADD_TRIANGLE(1, 4, 7)
ADD_TRIANGLE(1, 7, 2)
@ -3181,7 +3181,7 @@ SDL_RenderDrawLinesF(SDL_Renderer * renderer,
ADD_TRIANGLE(5, 0, 3)
ADD_TRIANGLE(5, 3, 6)
}
} else if (p.x == q.x) {
} else if (SDL_FLT_EQUAL(p.x, q.x)) {
if (p.y < q.y) {
ADD_TRIANGLE(2, 5, 4)
ADD_TRIANGLE(2, 4, 3)
@ -3231,7 +3231,7 @@ SDL_RenderDrawLinesF(SDL_Renderer * renderer,
SDL_small_free(xy, isstack1);
SDL_small_free(indices, isstack2);
} else if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
} else if (!SDL_FLT_EQUAL(renderer->scale.x, 1.0f) || !SDL_FLT_EQUAL(renderer->scale.y, 1.0f)) {
retval = RenderDrawLinesWithRectsF(renderer, points, count);
} else {
retval = QueueCmdDrawLines(renderer, points, count);
@ -3625,7 +3625,7 @@ SDL_RenderCopyExF(SDL_Renderer * renderer, SDL_Texture * texture,
int retval;
int use_rendergeometry;
if (flip == SDL_FLIP_NONE && (int)(angle/360) == angle/360) { /* fast path when we don't need rotation or flipping */
if (flip == SDL_FLIP_NONE && SDL_FLT_EQUAL((int)(angle/360), angle/360)) { /* fast path when we don't need rotation or flipping */
return SDL_RenderCopyF(renderer, texture, srcrect, dstrect);
}
@ -3800,19 +3800,19 @@ remap_one_indice(
int col0_, col1_;
xy0_ = (const float *)((const char*)xy + prev * xy_stride);
xy1_ = (const float *)((const char*)xy + k * xy_stride);
if (xy0_[0] != xy1_[0]) {
if (!SDL_FLT_EQUAL(xy0_[0], xy1_[0])) {
return k;
}
if (xy0_[1] != xy1_[1]) {
if (!SDL_FLT_EQUAL(xy0_[1], xy1_[1])) {
return k;
}
if (texture) {
uv0_ = (const float *)((const char*)uv + prev * uv_stride);
uv1_ = (const float *)((const char*)uv + k * uv_stride);
if (uv0_[0] != uv1_[0]) {
if (!SDL_FLT_EQUAL(uv0_[0], uv1_[0])) {
return k;
}
if (uv0_[1] != uv1_[1]) {
if (SDL_FLT_EQUAL(uv0_[1], uv1_[1])) {
return k;
}
}
@ -3999,7 +3999,7 @@ SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer,
x2 = xy2_[0]; y2 = xy2_[1];
/* Check if triangle A B C is rectangle */
if ((x0 == x2 && y1 == y2) || (y0 == y2 && x1 == x2)){
if ((SDL_FLT_EQUAL(x0, x2) && SDL_FLT_EQUAL(y1, y2)) || (SDL_FLT_EQUAL(y0, y2) && SDL_FLT_EQUAL(x1, x2))){
/* ok */
} else {
is_quad = 0;
@ -4012,7 +4012,7 @@ SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer,
x2 = xy2_[0]; y2 = xy2_[1];
/* Check if triangle A B C2 is rectangle */
if ((x0 == x2 && y1 == y2) || (y0 == y2 && x1 == x2)){
if ((SDL_FLT_EQUAL(x0, x2) && SDL_FLT_EQUAL(y1, y2)) || (SDL_FLT_EQUAL(y0, y2) && SDL_FLT_EQUAL(x1, x2))){
/* ok */
} else {
is_quad = 0;
@ -4087,7 +4087,7 @@ SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer,
SDL_Log("Rect-COPY: RGB %d %d %d - Alpha:%d - texture=%p: src=(%d,%d, %d x %d) dst (%f, %f, %f x %f)", col0_.r, col0_.g, col0_.b, col0_.a,
(void *)texture, s.x, s.y, s.w, s.h, d.x, d.y, d.w, d.h);
#endif
} else if (d.w != 0.0f && d.h != 0.0f) { /* Rect, no texture */
} else if (!SDL_FLT_IS_ZERO(d.w) && !SDL_FLT_IS_ZERO(d.h)) { /* Rect, no texture */
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(renderer, col0_.r, col0_.g, col0_.b, col0_.a);
SDL_RenderFillRectF(renderer, &d);

View file

@ -311,7 +311,7 @@ Blit_to_Screen(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *surface, SDL_Re
{
int retval;
/* Renderer scaling, if needed */
if (scale_x != 1.0f || scale_y != 1.0f) {
if (!SDL_FLT_EQUAL(scale_x, 1.0f) || !SDL_FLT_EQUAL(scale_y, 1.0f)) {
SDL_Rect r;
r.x = (int)((float) dstrect->x * scale_x);
r.y = (int)((float) dstrect->y * scale_y);

View file

@ -152,7 +152,7 @@ SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FP
{
/* The trig code below gets the wrong size (due to FP inaccuracy?) when angle is a multiple of 90 degrees */
int angle90 = (int)(angle/90);
if(angle90 == angle/90) { /* if the angle is a multiple of 90 degrees */
if(SDL_FLT_EQUAL(angle90, angle/90)) { /* if the angle is a multiple of 90 degrees */
angle90 %= 4;
if(angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
if(angle90 & 1) {
@ -540,7 +540,7 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int
* multiples of 90 degrees.
*/
angle90 = (int)(angle/90);
if (angle90 == angle/90) {
if (SDL_FLT_EQUAL(angle90, angle/90)) {
angle90 %= 4;
if (angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
} else {

View file

@ -1166,10 +1166,10 @@ SDL_CalculateGammaRamp(float gamma, Uint16 * ramp)
}
/* 0.0 gamma is all black */
if (gamma == 0.0f) {
if (SDL_FLT_IS_ZERO(gamma)) {
SDL_memset(ramp, 0, 256 * sizeof(Uint16));
return;
} else if (gamma == 1.0f) {
} else if (SDL_FLT_EQUAL(gamma, 1.0f)) {
/* 1.0 gamma is identity */
for (i = 0; i < 256; ++i) {
ramp[i] = (i << 8) | i;

View file

@ -345,7 +345,7 @@ SDL_INTERSECTRECTANDLINE(const RECTTYPE * rect, SCALARTYPE *X1, SCALARTYPE *Y1,
return SDL_FALSE;
}
if (y1 == y2) { /* Horizontal line, easy to clip */
if (SDL_FLT_EQUAL(y1, y2)) { /* Horizontal line, easy to clip */
if (x1 < rectx1) {
*X1 = rectx1;
} else if (x1 > rectx2) {
@ -359,7 +359,7 @@ SDL_INTERSECTRECTANDLINE(const RECTTYPE * rect, SCALARTYPE *X1, SCALARTYPE *Y1,
return SDL_TRUE;
}
if (x1 == x2) { /* Vertical line, easy to clip */
if (SDL_FLT_EQUAL(x1, x2)) { /* Vertical line, easy to clip */
if (y1 < recty1) {
*Y1 = recty1;
} else if (y1 > recty2) {