From 26feefa91ce5016de507c658bfafb4d3b84b8a6c Mon Sep 17 00:00:00 2001 From: Joel Kuntz Date: Mon, 6 May 2024 09:23:37 -0300 Subject: [PATCH] Add notes for remap's return when istart and istop are the same MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: RĂ©mi Verschelde Co-Authored-By: kleonc <9283098+kleonc@users.noreply.github.com> --- doc/classes/@GlobalScope.xml | 1 + tests/core/math/test_math_funcs.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index 26bf5151358..4b32acaaa0b 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -1097,6 +1097,7 @@ remap(75, 0, 100, -1, 1) # Returns 0.5 [/codeblock] For complex use cases where multiple ranges are needed, consider using [Curve] or [Gradient] instead. + [b]Note:[/b] If [code]istart == istop[/code], the return value is undefined (most likely NaN, INF, or -INF). diff --git a/tests/core/math/test_math_funcs.h b/tests/core/math/test_math_funcs.h index 0a9d9c97d98..f2eae3a20d2 100644 --- a/tests/core/math/test_math_funcs.h +++ b/tests/core/math/test_math_funcs.h @@ -381,6 +381,9 @@ TEST_CASE_TEMPLATE("[Math] remap", T, float, double) { CHECK(Math::remap((T)-100.0, (T)-100.0, (T)-200.0, (T)0.0, (T)-1000.0) == doctest::Approx((T)0.0)); CHECK(Math::remap((T)-200.0, (T)-100.0, (T)-200.0, (T)0.0, (T)-1000.0) == doctest::Approx((T)-1000.0)); CHECK(Math::remap((T)-250.0, (T)-100.0, (T)-200.0, (T)0.0, (T)-1000.0) == doctest::Approx((T)-1500.0)); + + // Note: undefined behaviour can happen when `p_istart == p_istop`. We don't bother testing this as it will + // vary between hardware and compilers properly implementing IEEE 754. } TEST_CASE_TEMPLATE("[Math] angle_difference", T, float, double) {