Convert a lot of floating-point constants to single precision

For reasons now lost to history, Puzzles generally uses single-precision
floating point.  However, C floating-point constants are by default
double-precision, and if they're then operated on along with a
single-precision variable the value of the variable gets promoted to
double precision, then the operation gets done, and then often the
result gets converted back to single precision again.

This is obviously silly, so I've used Clang's "-Wdouble-promotion" to
find instances of this and mark the constants as single-precision as
well.  This is a bit awkward for PI, which ends up with a cast.  Maybe
there should be a PIF, or maybe PI should just be single-precision.

This doesn't eliminate all warnings from -Wdouble-promotion.  Some of
the others might merit fixing but adding explicit casts to double just
to shut the compiler up would be going too far, I feel.
This commit is contained in:
Ben Harris
2023-02-18 18:52:21 +00:00
parent 26c7f3aa28
commit e8ac0381f9
11 changed files with 32 additions and 32 deletions

12
net.c
View File

@ -2606,8 +2606,8 @@ static void draw_wires(drawing *dr, int cx, int cy, int radius,
for (i = 0; i < npoints; i++) {
rotated_coords(&xf, &yf, matrix, cx, cy, fpoints[2*i], fpoints[2*i+1]);
points[2*i] = 0.5 + xf;
points[2*i+1] = 0.5 + yf;
points[2*i] = 0.5F + xf;
points[2*i+1] = 0.5F + yf;
}
draw_polygon(dr, points, npoints, colour, colour);
@ -2747,8 +2747,8 @@ static void draw_tile(drawing *dr, game_drawstate *ds, int x, int y,
* rotated by an arbitrary angle about that centre point.
*/
if (tile & TILE_ROTATING) {
matrix[0] = (float)cos(angle * PI / 180.0);
matrix[2] = (float)sin(angle * PI / 180.0);
matrix[0] = (float)cos(angle * (float)PI / 180.0F);
matrix[2] = (float)sin(angle * (float)PI / 180.0F);
} else {
matrix[0] = 1.0F;
matrix[2] = 0.0F;
@ -2787,8 +2787,8 @@ static void draw_tile(drawing *dr, game_drawstate *ds, int x, int y,
float x, y;
rotated_coords(&x, &y, matrix, cx, cy,
boxr * points[i], boxr * points[i+1]);
points[i] = x + 0.5;
points[i+1] = y + 0.5;
points[i] = x + 0.5F;
points[i+1] = y + 0.5F;
}
draw_polygon(dr, points, 4, col, COL_WIRE);