From 0f8911e29bd68af82cd6403e2c081f939477e265 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 25 Jun 2024 14:06:13 -0300 Subject: src/math.h: Add max_size() function --- src/math.c | 3 +++ src/math.h | 5 +++++ tests/math.c | 14 ++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/src/math.c b/src/math.c index 4e9fee0..143a48d 100644 --- a/src/math.c +++ b/src/math.c @@ -41,3 +41,6 @@ mul_size(const size_t x, const size_t y, size_t *const out) { out: return rc; } + +extern inline size_t +max_size(const size_t x, const size_t y); diff --git a/src/math.h b/src/math.h index 4dab4a7..79b52f0 100644 --- a/src/math.h +++ b/src/math.h @@ -3,3 +3,8 @@ add_size(const size_t x, const size_t y, size_t *const out); int mul_size(const size_t x, const size_t y, size_t *const out); + +inline size_t +max_size(size_t x, size_t y) { + return x > y ? x : y; +} diff --git a/tests/math.c b/tests/math.c index 2aefa59..5dcebda 100644 --- a/tests/math.c +++ b/tests/math.c @@ -122,6 +122,19 @@ test_mul_size(void) { } } +static void +test_max_size(void) { + test_start("max_size()"); + + { + testing("simplistic cases"); + assert(max_size(0U, 0U) == 0U); + assert(max_size(1U, 0U) == 1U); + assert(max_size(10U, SIZE_MAX + 1U) == 10U); + test_ok(); + } +} + int main(void) { @@ -129,6 +142,7 @@ main(void) { test_add_size(); test_mul_size(); + test_max_size(); rc = EXIT_SUCCESS; return rc; -- cgit v1.2.3