realX_begin.h (4104B)
1 /* Copyright (C) 2013-2023, 2025 Vincent Forest (vaplv@free.fr) 2 * 3 * The RSys library is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published 5 * by the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * The RSys library is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */ 15 16 /* This file can be included once */ 17 #if defined(REALX_BEGIN_H) 18 #error The realX_begin.h header is already included 19 #endif 20 #define REALX_BEGIN_H 21 22 /* Check that the expected arguments are defined */ 23 #if !defined(REALX_DIMENSION__) || !defined(REAL_TYPE__) 24 #error Missing arguments 25 #endif 26 27 /* Check that internal macros are not already defined */ 28 #if defined(REAL_EPSILON__) \ 29 || defined(REAL_EPSILON_double) \ 30 || defined(REAL_EPSILON_float) \ 31 || defined(REAL_EQ_EPS__) \ 32 || defined(REAL_EQ_EPS_double) \ 33 || defined(REAL_EQ_EPS_float) \ 34 || defined(REAL_LETTER__) \ 35 || defined(REAL_LETTER_double) \ 36 || defined(REAL_LETTER_float) \ 37 || defined(REAL_LETTER_TYPE_COMPATIBLE__) \ 38 || defined(REAL_TYPE_COMPATIBLE__) \ 39 || defined(REAL_TYPE_COMPATIBLE_double) \ 40 || defined(REAL_TYPE_COMPATIBLE_float) \ 41 || defined(REALX_CAST__) \ 42 || defined(REALX_CTOR__) \ 43 || defined(REALX_FUNC__) \ 44 || defined(REALX_REAL_FUNC__) \ 45 || defined(SIZEOF_REALX__) 46 #error Unexpected macro definition 47 #endif 48 49 /* Define the epsilon for each real type */ 50 #define REAL_EPSILON__ CONCAT(REAL_EPSILON_, REAL_TYPE__) 51 #define REAL_EPSILON_double 1.e-8 52 #define REAL_EPSILON_float 1.e-6f 53 54 /* Define the eq_eps function for each type */ 55 #define REAL_EQ_EPS__ CONCAT(REAL_EQ_EPS_, REAL_TYPE__) 56 #define REAL_EQ_EPS_double eq_eps 57 #define REAL_EQ_EPS_float eq_epsf 58 59 /* Define the suffix/prefix letter for each real type */ 60 #define REAL_LETTER__ CONCAT(REAL_LETTER_, REAL_TYPE__) 61 #define REAL_LETTER_float f 62 #define REAL_LETTER_double d 63 #define REAL_LETTER_TYPE_COMPATIBLE__ \ 64 CONCAT(REAL_LETTER_, REAL_TYPE_COMPATIBLE__) 65 66 /* Define the type that is compatible to the current real type */ 67 #define REAL_TYPE_COMPATIBLE__ CONCAT(REAL_TYPE_COMPATIBLE_, REAL_TYPE__) 68 #define REAL_TYPE_COMPATIBLE_double float 69 #define REAL_TYPE_COMPATIBLE_float double 70 71 /* Define name of the cast function */ 72 #define REALX_CAST__ REALX_FUNC__ \ 73 (CONCAT(set_, CONCAT(REAL_LETTER_TYPE_COMPATIBLE__, REALX_DIMENSION__))) 74 75 /* Define the realX constructor from reals */ 76 #define REALX_CTOR__ CONCAT(REAL_LETTER__, REALX_DIMENSION__) 77 78 79 /* Define the function name generator */ 80 #define REALX_FUNC__(Func) \ 81 CONCAT(CONCAT(CONCAT(REAL_LETTER__, REALX_DIMENSION__), _), Func) 82 83 /* Define the name generator for the realX x real -> realX functions */ 84 #define REALX_REAL_FUNC__(Func) CONCAT(REALX_FUNC__(Func), REAL_LETTER__) 85 86 /* Helper macro */ 87 #define SIZEOF_REALX__ sizeof(REAL_TYPE__[REALX_DIMENSION__]) 88 89 /* Check the validity of the vector dimension */ 90 #include "rsys.h" 91 STATIC_ASSERT(REALX_DIMENSION__ > 1, Unexpected_value);