diff options
| author | Ben Harris <bjh21@bjh21.me.uk> | 2023-02-18 18:52:21 +0000 |
|---|---|---|
| committer | Ben Harris <bjh21@bjh21.me.uk> | 2023-02-19 12:41:13 +0000 |
| commit | e8ac0381f976f2dfd70fbe52e0ec59c1a8da9df6 (patch) | |
| tree | 325d20828f8389a2c5f287f56b5e8082b4d0c2a3 /twiddle.c | |
| parent | 26c7f3aa285a45176c940afebe3885ad2be2ed65 (diff) | |
| download | puzzles-e8ac0381f976f2dfd70fbe52e0ec59c1a8da9df6.zip puzzles-e8ac0381f976f2dfd70fbe52e0ec59c1a8da9df6.tar.gz puzzles-e8ac0381f976f2dfd70fbe52e0ec59c1a8da9df6.tar.bz2 puzzles-e8ac0381f976f2dfd70fbe52e0ec59c1a8da9df6.tar.xz | |
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.
Diffstat (limited to 'twiddle.c')
| -rw-r--r-- | twiddle.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -884,8 +884,8 @@ static void rotate(int *xy, struct rotation *rot) xf2 = rot->c * xf + rot->s * yf; yf2 = - rot->s * xf + rot->c * yf; - xy[0] = (int)(xf2 + rot->ox + 0.5); /* round to nearest */ - xy[1] = (int)(yf2 + rot->oy + 0.5); /* round to nearest */ + xy[0] = (int)(xf2 + rot->ox + 0.5F); /* round to nearest */ + xy[1] = (int)(yf2 + rot->oy + 0.5F); /* round to nearest */ } } @@ -1072,7 +1072,7 @@ static int highlight_colour(float angle) COL_LOWLIGHT, }; - return colours[(int)((angle + 2*PI) / (PI/16)) & 31]; + return colours[(int)((angle + 2*(float)PI) / ((float)PI/16)) & 31]; } static float game_anim_length_real(const game_state *oldstate, @@ -1196,7 +1196,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds, rot->cw = rot->ch = TILE_SIZE * state->n; rot->ox = rot->cx + rot->cw/2; rot->oy = rot->cy + rot->ch/2; - angle = (float)((-PI/2 * lastr) * (1.0 - animtime / anim_max)); + angle = ((-(float)PI/2 * lastr) * (1.0F - animtime / anim_max)); rot->c = (float)cos(angle); rot->s = (float)sin(angle); |