- Finished non-natural Exponential Tests

- Finished Common Tests

TODO:
Math Constants
exp tests
log tests
This commit is contained in:
2025-06-29 17:55:55 -04:00
parent f2ff863b3a
commit f38cf5fb51
6 changed files with 162 additions and 11 deletions

View File

@@ -293,15 +293,15 @@ template<> struct numeric_limits<float>
static constexpr int max_exponent = FLT_MAX_EXP; static constexpr int max_exponent = FLT_MAX_EXP;
static constexpr int max_exponent10 = FLT_MAX_10_EXP; static constexpr int max_exponent10 = FLT_MAX_10_EXP;
static constexpr double min() { return -FLT_MAX; } static constexpr float min() { return -FLT_MAX; }
static constexpr double max() { return FLT_MAX; } static constexpr float max() { return FLT_MAX; }
static constexpr double lowest() { return FLT_MIN; } static constexpr float lowest() { return FLT_MIN; }
static constexpr double epsilon() { return FLT_EPSILON; } static constexpr float epsilon() { return FLT_EPSILON; }
static constexpr double round_error() { return FLT_ROUND_ERR; } static constexpr float round_error() { return FLT_ROUND_ERR; }
static constexpr double infinity() { return FLT_INF; } static constexpr float infinity() { return FLT_INF; }
static constexpr double quiet_NaN() { return FLT_QUIET_NAN; } static constexpr float quiet_NaN() { return FLT_QUIET_NAN; }
static constexpr double signaling_NaN() { return FLT_SIGNALING_NAN; } static constexpr float signaling_NaN() { return FLT_SIGNALING_NAN; }
static constexpr double denorm_min() { return FLT_DENORM_MIN; } static constexpr float denorm_min() { return FLT_DENORM_MIN; }
}; };
// Overload for the bultin double precision floating point type // Overload for the bultin double precision floating point type

View File

@@ -907,7 +907,7 @@ constexpr vector<genType, i...> step(const vector<genType, i...>& edge, const ve
/// \param x \f$x\f$ coordinate input /// \param x \f$x\f$ coordinate input
template<typename genType> requires(is_floating_point_v<genType>) template<typename genType> requires(is_floating_point_v<genType>)
constexpr genType smoothstep(genType edge0, genType edge1, genType x) constexpr genType smoothstep(genType edge0, genType edge1, genType x)
{ genType t = fennec::clamp((x - edge0) / (edge1 - edge0)); return t * t * (3 - 2 * t); } { genType t = fennec::clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f); return t * t * (3 - 2 * t); }
// Vector Specializations ---------------------------------------------------------------------------------------------- // Vector Specializations ----------------------------------------------------------------------------------------------

View File

@@ -16,6 +16,7 @@ add_executable(fennec-test main.cpp
tests/lang/test_bits.h tests/lang/test_bits.h
tests/lang/test_sequences.h tests/lang/test_sequences.h
tests/math/test_common.h tests/math/test_common.h
tests/math/test_exponential.h
) )
target_link_libraries(fennec-test PRIVATE target_link_libraries(fennec-test PRIVATE

View File

@@ -144,10 +144,73 @@ inline void fennec_test_math_common()
fennec_test_run(fennec::uintBitsToFloat(0x3f800000u), 1.0f); fennec_test_run(fennec::uintBitsToFloat(0x3f800000u), 1.0f);
fennec_test_run(fennec::uintBitsToFloat(0xbf800000u), -1.0f); fennec_test_run(fennec::uintBitsToFloat(0xbf800000u), -1.0f);
fennec_test_spacer(1);
fennec_test_run(fennec::fma( 1, 2, 3), 5);
fennec_test_run(fennec::fma(-1, 2, -3), -5);
fennec_test_run(fennec::fma( 1, -2, 3), 1);
fennec_test_spacer(1);
fennec_test_run([]() -> float { int i; float f = fennec::frexp(2.4f, i); return fennec::ldexp(f, i); }(), 2.4f);
fennec_test_run([]() -> float { int i; float f = fennec::frexp(2.5f, i); return fennec::ldexp(f, i); }(), 2.5f);
fennec_test_run([]() -> float { int i; float f = fennec::frexp(2.6f, i); return fennec::ldexp(f, i); }(), 2.6f);
fennec_test_spacer(2); fennec_test_spacer(2);
fennec_test_section("Comparison Functions");
fennec_test_spacer(1);
fennec_test_run(min(2.0f, 1.0f), 1.0f);
fennec_test_run(min(-fennec::numeric_limits<float>::infinity(), 0.0f), -fennec::numeric_limits<float>::infinity());
fennec_test_run(min( fennec::numeric_limits<float>::quiet_NaN(), -1.0f), -1.0f);
fennec_test_spacer(1);
fennec_test_run(max(2.0f, 1.0f), 2.0f);
fennec_test_run(max(-fennec::numeric_limits<float>::infinity(), 0.0f), 0.0f);
fennec_test_run(max( fennec::numeric_limits<float>::quiet_NaN(), -1.0f), -1.0f);
fennec_test_spacer(1);
fennec_test_run(clamp(-0.5f, 0.0f, 1.0f), 0.0f);
fennec_test_run(clamp( 0.5f, 0.0f, 1.0f), 0.5f);
fennec_test_run(clamp( 1.5f, 0.0f, 1.0f), 1.0f);
fennec_test_spacer(2);
fennec_test_section("Curves");
fennec_test_spacer(1);
fennec_test_run(step(2.5f, 2.4f), 0.0f);
fennec_test_run(step(2.5f, 2.5f), 1.0f);
fennec_test_run(step(2.5f, 2.6f), 1.0f);
fennec_test_spacer(1);
fennec_test_run(smoothstep(0.0f, 1.0f, -0.5f), 0.0f);
fennec_test_run(smoothstep(0.0f, 1.0f, 0.5f), 0.5f);
fennec_test_run(smoothstep(0.0f, 1.0f, 1.5f), 1.0f);
fennec_test_spacer(1);
fennec_test_run(mix(0.0f, 1.0f, -0.5f), -0.5f);
fennec_test_run(mix(0.0f, 1.0f, 0.5f), 0.5f);
fennec_test_run(mix(0.0f, 1.0f, 1.5f), 1.5f);
fennec_test_spacer(1);
fennec_test_run(mix(0.0f, 1.0f, false), 0.0f);
fennec_test_run(mix(0.0f, 1.0f, true), 1.0f);
fennec_test_spacer(2);
} }
} }

View File

@@ -0,0 +1,80 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// 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/>.
// =====================================================================================================================
#ifndef FENNEC_TEST_MATH_EXPONENTIAL_H
#define FENNEC_TEST_MATH_EXPONENTIAL_H
#include <fennec/math/exponential.h>
namespace fennec
{
namespace test
{
inline void fennec_test_math_exponential()
{
fennec_test_spacer(1);
fennec_test_run(fennec::pow(1.0f, 2.0f), 1.0f);
fennec_test_run(fennec::pow(2.0f, 0.0f), 1.0f);
fennec_test_run(fennec::pow(2.0f, 1.0f), 1.0f);
fennec_test_run(fennec::pow(2.0f, 2.0f), 4.0f);
fennec_test_spacer(1);
//fennec_test_run(fennec::exp())
fennec_test_spacer(1);
fennec_test_run(fennec::exp2(-1.0f), 0.5f);
fennec_test_run(fennec::exp2( 0.0f), 1.0f);
fennec_test_run(fennec::exp2( 1.0f), 2.0f);
fennec_test_run(fennec::exp2( 2.0f), 4.0f);
fennec_test_spacer(1);
//fennec_test_run(fennec::log())
fennec_test_spacer(1);
fennec_test_run(fennec::log2(1.0f), 0.0f);
fennec_test_run(fennec::log2(2.0f), 1.0f);
fennec_test_run(fennec::log2(4.0f), 2.0f);
fennec_test_spacer(1);
fennec_test_run(fennec::sqrt(1.0f), 1.0f);
fennec_test_run(fennec::sqrt(4.0f), 2.0f);
fennec_test_run(fennec::sqrt(9.0f), 3.0f);
fennec_test_spacer(1);
fennec_test_run(fennec::inversesqrt(1.0f), 1.0f / 1.0f);
fennec_test_run(fennec::inversesqrt(4.0f), 1.0f / 2.0f);
fennec_test_run(fennec::inversesqrt(9.0f), 1.0f / 3.0f);
fennec_test_spacer(2);
}
}
}
#endif // FENNEC_TEST_MATH_EXPONENTIAL_H

View File

@@ -19,10 +19,12 @@
#ifndef FENNEC_TEST_MATH_H #ifndef FENNEC_TEST_MATH_H
#define FENNEC_TEST_MATH_H #define FENNEC_TEST_MATH_H
#include "math/test_common.h"
#include "math/test_scalar.h" #include "math/test_scalar.h"
#include "math/test_vector.h" #include "math/test_vector.h"
#include "math/test_matrix.h" #include "math/test_matrix.h"
#include "math/test_common.h"
#include "math/test_exponential.h"
#include "math/test_geometric.h" #include "math/test_geometric.h"
namespace fennec namespace fennec
@@ -53,6 +55,11 @@ inline void fennec_test_math()
fennec_test_math_common(); fennec_test_math_common();
fennec_test_spacer(3); fennec_test_spacer(3);
fennec_test_subheader("exponential tests");
fennec_test_spacer(2);
fennec_test_math_exponential();
fennec_test_spacer(3);
fennec_test_subheader("geometric tests"); fennec_test_subheader("geometric tests");
fennec_test_spacer(2); fennec_test_spacer(2);
fennec_test_math_geometric(); fennec_test_math_geometric();