From 9821a2ab15e27a0e0a9cc4de909251a7d4366374 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Thu, 27 Nov 2025 00:55:44 +0000 Subject: [PATCH] Define basic type aliases and useful functions/macros for use throughout the system --- src/base.hpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/base.hpp diff --git a/src/base.hpp b/src/base.hpp new file mode 100644 index 0000000..b519dde --- /dev/null +++ b/src/base.hpp @@ -0,0 +1,53 @@ +/* base.hpp: Basic definitions + * Created: 2025-11-27 + * Author: Aryadev Chavali + * License: See end of file + * Commentary: + */ + +#ifndef BASE_HPP +#define BASE_HPP + +#include +#include +#include + +#define MIN(A, B) ((A) < (B) ? (A) : (B)) +#define MAX(A, B) ((B) < (A) ? (A) : (B)) + +using u8 = uint8_t; +using u16 = uint16_t; +using u32 = uint32_t; +using u64 = uint64_t; + +using i8 = int8_t; +using i16 = int16_t; +using i32 = int32_t; +using i64 = int64_t; + +static_assert(sizeof(float) == 4, "f32 requires 4 byte floats"); +static_assert(sizeof(double) == 8, "f64 requires 8 byte doubles"); +using f32 = float; +using f64 = double; + +using index_t = i64; + +inline bool index_has_value(index_t i) +{ + return i >= 0; +} + +#endif + +/* Copyright (C) 2025 Aryadev Chavali + + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License Version 2 for + * details. + + * You may distribute and modify this code under the terms of the GNU General + * Public License Version 2, which you should have received a copy of along with + * this program. If not, please go to . + + */