134 lines
10 KiB
C++
134 lines
10 KiB
C++
// =====================================================================================================================
|
|
// fennec-metaprogramming, a program to generate metaprogramming intrinsics
|
|
// Copyright © 2025 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/>.
|
|
// =====================================================================================================================
|
|
|
|
#include <fstream>
|
|
#include <cmath>
|
|
|
|
int main(int, const char**)
|
|
{
|
|
std::ofstream flt("float.h");
|
|
|
|
flt << "// =====================================================================================================================" << std::endl;
|
|
flt << "// fennec, a free and open source game engine" << std::endl;
|
|
flt << "// Copyright © 2025 Medusa Slockbower" << std::endl;
|
|
flt << "//" << std::endl;
|
|
flt << "// This program is free software: you can redistribute it and/or modify" << std::endl;
|
|
flt << "// it under the terms of the GNU General Public License as published by" << std::endl;
|
|
flt << "// the Free Software Foundation, either version 3 of the License, or" << std::endl;
|
|
flt << "// (at your option) any later version." << std::endl;
|
|
flt << "//" << std::endl;
|
|
flt << "// This program is distributed in the hope that it will be useful," << std::endl;
|
|
flt << "// but WITHOUT ANY WARRANTY; without even the implied warranty of" << std::endl;
|
|
flt << "// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" << std::endl;
|
|
flt << "// GNU General Public License for more details." << std::endl;
|
|
flt << "//" << std::endl;
|
|
flt << "// You should have received a copy of the GNU General Public License" << std::endl;
|
|
flt << "// along with this program. If not, see <https://www.gnu.org/licenses/>." << std::endl;
|
|
flt << "// =====================================================================================================================" << std::endl;
|
|
|
|
flt << "" << std::endl;
|
|
|
|
flt << "///" << std::endl;
|
|
flt << "/// \\file float.h" << std::endl;
|
|
flt << "/// \\brief metaprogramming floating point type info" << std::endl;
|
|
flt << "///" << std::endl;
|
|
flt << "///" << std::endl;
|
|
flt << "/// \\details this file is automatically generated for the current build environment" << std::endl;
|
|
flt << "///" << std::endl;
|
|
flt << "/// \\copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))" << std::endl;
|
|
flt << "///" << std::endl;
|
|
flt << "///" << std::endl;
|
|
|
|
flt << "" << std::endl;
|
|
|
|
flt << "#ifndef FENNEC_LANG_FLOAT_H" << std::endl;
|
|
flt << "#define FENNEC_LANG_FLOAT_H" << std::endl;
|
|
|
|
flt << "" << std::endl;
|
|
|
|
flt << "#include <fennec/memory/bits.h>" << std::endl;
|
|
|
|
flt << "" << std::endl;
|
|
|
|
// TODO: Fix this to generate info without using the c++stdlib for platforms without this available.
|
|
|
|
flt << "#define FLT_HAS_INFINITY " << std::dec << std::numeric_limits<float>::has_infinity << std::endl;
|
|
flt << "#define FLT_HAS_QUIET_NAN " << std::dec << std::numeric_limits<float>::has_quiet_NaN << std::endl;
|
|
flt << "#define FLT_HAS_SIGNALING_NAN " << std::dec << std::numeric_limits<float>::has_signaling_NaN << std::endl;
|
|
flt << "#define FLT_HAS_DENORM " << std::dec << std::numeric_limits<float>::has_denorm << std::endl;
|
|
flt << "#define FLT_HAS_DENORM_LOSS " << std::dec << std::numeric_limits<float>::has_denorm_loss << std::endl;
|
|
flt << "#define FLT_ROUNDS " << std::dec << std::numeric_limits<float>::round_style << std::endl;
|
|
flt << "#define FLT_IS_IEC559 " << std::dec << std::numeric_limits<float>::is_iec559 << std::endl;
|
|
flt << "#define FLT_MANT_DIG " << std::dec << std::numeric_limits<float>::digits << std::endl;
|
|
flt << "#define FLT_DIG " << std::dec << std::numeric_limits<float>::digits10 << std::endl;
|
|
flt << "#define FLT_DECIMAL_DIG " << std::dec << std::numeric_limits<float>::max_digits10 << std::endl;
|
|
flt << "#define FLT_RADIX " << std::dec << std::numeric_limits<float>::radix << std::endl;
|
|
flt << "#define FLT_MIN_EXP " << std::dec << std::numeric_limits<float>::min_exponent << std::endl;
|
|
flt << "#define FLT_MAX_EXP " << std::dec << std::numeric_limits<float>::max_exponent << std::endl;
|
|
flt << "#define FLT_MIN_10_EXP " << std::dec << std::numeric_limits<float>::min_exponent10 << std::endl;
|
|
flt << "#define FLT_MAX_10_EXP " << std::dec << std::numeric_limits<float>::max_exponent10 << std::endl;
|
|
flt << "#define FLT_TRAPS " << std::dec << std::numeric_limits<float>::traps << std::endl;
|
|
flt << "#define FLT_TINYNESS_BEFORE " << std::dec << std::numeric_limits<float>::tinyness_before << std::endl;
|
|
|
|
flt << "#define FLT_MIN " << "fennec::bit_cast<float>(0x" << std::hex << std::bit_cast<int>(std::numeric_limits<float>::min() ) << ")" << std::endl;
|
|
flt << "#define FLT_MAX " << "fennec::bit_cast<float>(0x" << std::hex << std::bit_cast<int>(std::numeric_limits<float>::max() ) << ")" << std::endl;
|
|
flt << "#define FLT_EPSILON " << "fennec::bit_cast<float>(0x" << std::hex << std::bit_cast<int>(std::numeric_limits<float>::epsilon() ) << ")" << std::endl;
|
|
flt << "#define FLT_INF " << "fennec::bit_cast<float>(0x" << std::hex << std::bit_cast<int>(std::numeric_limits<float>::infinity() ) << ")" << std::endl;
|
|
flt << "#define FLT_QUIET_NAN " << "fennec::bit_cast<float>(0x" << std::hex << std::bit_cast<int>(std::numeric_limits<float>::quiet_NaN() ) << ")" << std::endl;
|
|
flt << "#define FLT_SIGNALING_NAN " << "fennec::bit_cast<float>(0x" << std::hex << std::bit_cast<int>(std::numeric_limits<float>::signaling_NaN()) << ")" << std::endl;
|
|
flt << "#define FLT_DENORM_MIN " << "fennec::bit_cast<float>(0x" << std::hex << std::bit_cast<int>(std::numeric_limits<float>::denorm_min() ) << ")" << std::endl;
|
|
flt << "#define FLT_ROUND_ERR " << "fennec::bit_cast<float>(0x" << std::hex << std::bit_cast<int>(std::numeric_limits<float>::round_error() ) << ")" << std::endl;
|
|
|
|
flt << "" << std::endl;
|
|
|
|
flt << "#define DBL_HAS_INFINITY " << std::dec << std::numeric_limits<double>::has_infinity << std::endl;
|
|
flt << "#define DBL_HAS_QUIET_NAN " << std::dec << std::numeric_limits<double>::has_quiet_NaN << std::endl;
|
|
flt << "#define DBL_HAS_SIGNALING_NAN " << std::dec << std::numeric_limits<double>::has_signaling_NaN << std::endl;
|
|
flt << "#define DBL_HAS_DENORM " << std::dec << std::numeric_limits<double>::has_denorm << std::endl;
|
|
flt << "#define DBL_HAS_DENORM_LOSS " << std::dec << std::numeric_limits<double>::has_denorm_loss << std::endl;
|
|
flt << "#define DBL_ROUNDS " << std::dec << std::numeric_limits<double>::round_style << std::endl;
|
|
flt << "#define DBL_IS_IEC559 " << std::dec << std::numeric_limits<double>::is_iec559 << std::endl;
|
|
flt << "#define DBL_MANT_DIG " << std::dec << std::numeric_limits<double>::digits << std::endl;
|
|
flt << "#define DBL_DIG " << std::dec << std::numeric_limits<double>::digits10 << std::endl;
|
|
flt << "#define DBL_DECIMAL_DIG " << std::dec << std::numeric_limits<double>::max_digits10 << std::endl;
|
|
flt << "#define DBL_RADIX " << std::dec << std::numeric_limits<double>::radix << std::endl;
|
|
flt << "#define DBL_MIN_EXP " << std::dec << std::numeric_limits<double>::min_exponent << std::endl;
|
|
flt << "#define DBL_MAX_EXP " << std::dec << std::numeric_limits<double>::max_exponent << std::endl;
|
|
flt << "#define DBL_MIN_10_EXP " << std::dec << std::numeric_limits<double>::min_exponent10 << std::endl;
|
|
flt << "#define DBL_MAX_10_EXP " << std::dec << std::numeric_limits<double>::max_exponent10 << std::endl;
|
|
flt << "#define DBL_TRAPS " << std::dec << std::numeric_limits<double>::traps << std::endl;
|
|
flt << "#define DBL_TINYNESS_BEFORE " << std::dec << std::numeric_limits<double>::tinyness_before << std::endl;
|
|
|
|
flt << "#define DBL_MIN " << "fennec::bit_cast<double>(0x" << std::hex << std::bit_cast<long long>(std::numeric_limits<double>::min() ) << "l)" << std::endl;
|
|
flt << "#define DBL_MAX " << "fennec::bit_cast<double>(0x" << std::hex << std::bit_cast<long long>(std::numeric_limits<double>::max() ) << "l)" << std::endl;
|
|
flt << "#define DBL_EPSILON " << "fennec::bit_cast<double>(0x" << std::hex << std::bit_cast<long long>(std::numeric_limits<double>::epsilon() ) << "l)" << std::endl;
|
|
flt << "#define DBL_INF " << "fennec::bit_cast<double>(0x" << std::hex << std::bit_cast<long long>(std::numeric_limits<double>::infinity() ) << "l)" << std::endl;
|
|
flt << "#define DBL_QUIET_NAN " << "fennec::bit_cast<double>(0x" << std::hex << std::bit_cast<long long>(std::numeric_limits<double>::quiet_NaN() ) << "l)" << std::endl;
|
|
flt << "#define DBL_SIGNALING_NAN " << "fennec::bit_cast<double>(0x" << std::hex << std::bit_cast<long long>(std::numeric_limits<double>::signaling_NaN()) << "l)" << std::endl;
|
|
flt << "#define DBL_DENORM_MIN " << "fennec::bit_cast<double>(0x" << std::hex << std::bit_cast<long long>(std::numeric_limits<double>::denorm_min() ) << "l)" << std::endl;
|
|
flt << "#define DBL_ROUND_ERR " << "fennec::bit_cast<double>(0x" << std::hex << std::bit_cast<long long>(std::numeric_limits<double>::round_error() ) << "l)" << std::endl;
|
|
|
|
flt << "" << std::endl;
|
|
|
|
flt << "#endif // FENNEC_LANG_FLOAT_H" << std::endl;
|
|
|
|
flt.close();
|
|
|
|
return 0;
|
|
}
|