Generalize extrema functions

master
rexim 2019-12-10 20:32:16 +07:00
parent ed42f087d8
commit ea185ab734
3 changed files with 20 additions and 21 deletions

View File

@ -63,12 +63,12 @@ LevelEditor *create_level_editor(Cursor *cursor)
memset(level_editor->metadata.version, 0, METADATA_VERSION_MAX_SIZE);
memcpy(level_editor->metadata.version,
VERSION,
min_size_t(sizeof(VERSION), METADATA_VERSION_MAX_SIZE - 1));
MIN(size_t, sizeof(VERSION), METADATA_VERSION_MAX_SIZE - 1));
memset(level_editor->metadata.title, 0, METADATA_TITLE_MAX_SIZE);
memcpy(level_editor->metadata.title,
DEFAULT_LEVEL_TITLE,
min_size_t(sizeof(DEFAULT_LEVEL_TITLE), METADATA_TITLE_MAX_SIZE - 1));
MIN(size_t, sizeof(DEFAULT_LEVEL_TITLE), METADATA_TITLE_MAX_SIZE - 1));
level_editor->background_layer = create_background_layer(hexstr("fffda5"));

View File

@ -233,7 +233,7 @@ int main(int argc, char *argv[])
}
const int64_t end_frame_time = (int64_t) SDL_GetTicks();
SDL_Delay((unsigned int) max_int64(10, delta_time - (end_frame_time - begin_frame_time)));
SDL_Delay((unsigned int) MAX(int64_t, 10, delta_time - (end_frame_time - begin_frame_time)));
}
RETURN_LT(lt, 0);

View File

@ -3,25 +3,24 @@
#include <stdint.h>
// WARNING! Any attempts to "generalize" or "improve" this translation
// unit will result in an instantly closed Pull Request without any
// further discussion.
static inline
int64_t max_int64(int64_t a, int64_t b)
{
return a > b ? a : b;
}
#define MAX_INSTANCE(type) \
static inline \
type max_##type(type a, type b) { \
return a > b ? a : b; \
} \
static inline
size_t max_size_t(size_t a, size_t b)
{
return a > b ? a : b;
}
MAX_INSTANCE(int64_t)
MAX_INSTANCE(size_t)
#define MAX(type, a, b) max_##type(a, b)
static inline
size_t min_size_t(size_t a, size_t b)
{
return a < b ? a : b;
}
#define MIN_INSTANCE(type) \
static inline \
type min_##type(type a, type b) { \
return a < b ? a : b; \
} \
MIN_INSTANCE(int64_t)
MIN_INSTANCE(size_t)
#define MIN(type, a, b) min_##type(a, b)
#endif // EXTREMA_H_