Browse Source

Add notes for remap's return when istart and istop are the same

Co-Authored-By: Rémi Verschelde <[email protected]>
Co-Authored-By: kleonc <[email protected]>
Joel Kuntz 1 year ago
parent
commit
26feefa91c
2 changed files with 4 additions and 0 deletions
  1. 1 0
      doc/classes/@GlobalScope.xml
  2. 3 0
      tests/core/math/test_math_funcs.h

+ 1 - 0
doc/classes/@GlobalScope.xml

@@ -1097,6 +1097,7 @@
 				remap(75, 0, 100, -1, 1) # Returns 0.5
 				remap(75, 0, 100, -1, 1) # Returns 0.5
 				[/codeblock]
 				[/codeblock]
 				For complex use cases where multiple ranges are needed, consider using [Curve] or [Gradient] instead.
 				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).
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="rid_allocate_id">
 		<method name="rid_allocate_id">

+ 3 - 0
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)-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)-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));
 	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) {
 TEST_CASE_TEMPLATE("[Math] angle_difference", T, float, double) {