// =====================================================================================================================
//  fennec, a free and open source game engine
//  Copyright © 2025 - 2026  Medusa Slockbower
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  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 for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================

#ifndef FENNEC_MATH_DETAIL_MATH_H
#define FENNEC_MATH_DETAIL_MATH_H


// Handle including C math.h
// Unfortunately, each compiler needs its own if case in the macro chain below

#if FENNEC_COMPILER_CLANG // Clang

// Temporarily disable macro redefinition warning
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wbuiltin-macro-redefined"

// Undefine __cpluscplus macro to force using the C header
#pragma push_macro("__cplusplus")
#undef __cplusplus

// Include math.h
#include <math.h>

// Restore __cpluscplus definition and macro redefinition warning
#pragma pop_macro("__cplusplus")
#pragma clang diagnostic pop


#elif FENNEC_COMPILER_GCC // GCC

// This definition tells GCC to just use the C header, thanks GCC!!!
#ifndef _GLIBCXX_INCLUDE_NEXT_C_HEADERS
#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
#endif

#include <math.h>
#endif

#undef div
#undef acos
#undef asin
#undef atan
#undef atan2
#undef ceil
#undef cos
#undef cosh
#undef exp
#undef fabs
#undef floor
#undef fmod
#undef frexp
#undef ldexp
#undef log
#undef log10
#undef modf
#undef pow
#undef sin
#undef sinh
#undef sqrt
#undef tan
#undef tanh
#undef fpclassify
#undef signbit
#undef isfinite
#undef isnormal
#undef isnan
#undef isinf

#endif // FENNEC_MATH_DETAIL_MATH_H
