From 3b6480c5b0c968ad9f5a7cfb7ca494989be03629 Mon Sep 17 00:00:00 2001 From: Craig Robbins Date: Mon, 23 Feb 2015 16:25:14 +1000 Subject: Fix wrapDegrees family of functions wrapDegrees() (renamed to modulo360f) wrapDegrees_0_360 wrapDegrees_180 Minor errors were present in previous versions; see issue #2328 --- src/test.cpp | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'src/test.cpp') diff --git a/src/test.cpp b/src/test.cpp index 3b7c75c6e..350cab127 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -147,15 +147,45 @@ struct TestBase struct TestUtilities: public TestBase { + inline float ref_WrapDegrees180(float f) + { + // This is a slower alternative to the wrapDegrees_180() function; + // used as a reference for testing + float value = fmodf(f + 180, 360); + if (value < 0) + value += 360; + return value - 180; + } + + inline float ref_WrapDegrees_0_360(float f) + { + // This is a slower alternative to the wrapDegrees_0_360() function; + // used as a reference for testing + float value = fmodf(f, 360); + if (value < 0) + value += 360; + return value < 0 ? value + 360 : value; + } + + void Run() { - /*infostream<<"wrapDegrees(100.0) = "<