summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAmin Mesbah <mesbahamin@gmail.com>2017-11-11 16:58:53 -0800
committerAmin Mesbah <mesbahamin@gmail.com>2017-11-11 16:58:53 -0800
commitc3afec4d2182577d53dd9ca9ae95cdaa50951f05 (patch)
tree81ea4727eb2ec9857d7591a220bb3a22a19515cf /src
parent01aa330216076881c11618adf40dcf22c8ea019c (diff)
downloadohsp-c3afec4d2182577d53dd9ca9ae95cdaa50951f05.zip
ohsp-c3afec4d2182577d53dd9ca9ae95cdaa50951f05.tar.gz
Prevent unintended double promotion
- Append 'f' to intended float literals - Use cosf and sinf() consistently - Double promotion was found with the `Wdouble-promotion` GCC option
Diffstat (limited to 'src')
-rw-r--r--src/entity.c2
-rw-r--r--src/entity.h2
-rw-r--r--src/game.c18
-rw-r--r--src/game.h2
4 files changed, 12 insertions, 12 deletions
diff --git a/src/entity.c b/src/entity.c
index cb600bc..9765f7f 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -11,7 +11,7 @@ struct Vec2d vec2d_add(float angle1, float length1, float angle2, float length2)
struct Vec2d new_vec =
{
- .angle = 0.5 * M_PI - atan2f(y, x),
+ .angle = 0.5f * M_PI - atan2f(y, x),
.length = hypotf(x, y),
};
return new_vec;
diff --git a/src/entity.h b/src/entity.h
index 4136d90..f9c6a74 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -4,7 +4,7 @@
#include <stdint.h>
#ifndef M_PI
-#define M_PI (3.14159265358979323846264338327950288)
+#define M_PI 3.141592f
#endif
struct Entity
diff --git a/src/game.c b/src/game.c
index 776aac7..b43f8c9 100644
--- a/src/game.c
+++ b/src/game.c
@@ -83,10 +83,10 @@ void game_update(struct GameState *game_state, struct GameControllerInput game_i
game_state->thrust_vector02.length);
struct Entity *player = &game_state->player;
- entity_accelerate(player, game_state->thrust_vector_sum.angle, game_state->thrust_vector_sum.length * 0.01);
+ entity_accelerate(player, game_state->thrust_vector_sum.angle, game_state->thrust_vector_sum.length * 0.01f);
- player->x += player->speed * cos(player->angle);
- player->y += player->speed * sin(player->angle);
+ player->x += player->speed * cosf(player->angle);
+ player->y += player->speed * sinf(player->angle);
player->x = wrap(player->x, 0, field_width);
player->y = wrap(player->y, 0, field_height);
}
@@ -106,8 +106,8 @@ void game_render(struct OffscreenBuffer *buffer, float dt, struct GameState *gam
game_render_vector(buffer, &game_state->thrust_vector_sum, player.x, player.y, 5, 0xFF00FF);
game_render_circle(buffer,
- player.x + 100 * (player.speed * cos(player.angle)),
- player.y + 100 * (player.speed * sin(player.angle)),
+ player.x + 100 * (player.speed * cosf(player.angle)),
+ player.y + 100 * (player.speed * sinf(player.angle)),
5,
0x00FF00);
}
@@ -157,10 +157,10 @@ void game_render_line(struct OffscreenBuffer *buffer, float x0, float y0, float
{
game_set_pixel(buffer, x, y, color);
error += delta_err;
- if (error >= 0.5)
+ if (error >= 0.5f)
{
y += 1;
- error -= 1.0;
+ error -= 1.0f;
}
}
}
@@ -169,8 +169,8 @@ void game_render_line(struct OffscreenBuffer *buffer, float x0, float y0, float
void game_render_vector(struct OffscreenBuffer *buffer, struct Vec2d *v, float x0, float y0, float radius, uint32_t color)
{
- float x1 = x0 + 100 * (v->length * cos(v->angle));
- float y1 = y0 + 100 * (v->length * sin(v->angle));
+ float x1 = x0 + 100 * (v->length * cosf(v->angle));
+ float y1 = y0 + 100 * (v->length * sinf(v->angle));
game_render_line(buffer, x0, y0, x1, y1, color);
game_render_circle(buffer, x1, y1, radius, color);
}
diff --git a/src/game.h b/src/game.h
index 335de09..a3bb5de 100644
--- a/src/game.h
+++ b/src/game.h
@@ -16,7 +16,7 @@
#define MS_PER_UPDATE (SECOND / UPDATES_PER_SECOND)
#ifndef M_PI
-#define M_PI (3.14159265358979323846264338327950288)
+#define M_PI 3.141592f
#endif
#define COLOR_BACKGROUND 0x000000