Browse Source

merging redundant sprintf code and fixing an operator<< fixedpoint bug

Roberto Parolin 6 years ago
parent
commit
2bad24e6bd
3 changed files with 351 additions and 1080 deletions
  1. 2 2
      include/EAStdC/EAFixedPoint.h
  2. 311 1078
      source/EASprintfOrdered.cpp
  3. 38 0
      test/source/TestFixedPoint.cpp

+ 2 - 2
include/EAStdC/EAFixedPoint.h

@@ -283,8 +283,8 @@ struct FPTemplate
 	FPTemplate& operator^=(const FPTemplate& argValue) { value ^= argValue.value;          return *this;}
 	FPTemplate& operator^=(const int&        argValue) { value ^= (argValue<<upShiftInt);  return *this;} //Convert Fixed to int, then do operation
 
-	FPTemplate operator<<(int numBits) const { return value << numBits; }
-	FPTemplate operator>>(int numBits) const { return value << numBits; }
+	FPTemplate operator<<(int numBits) const { FPTemplate temp; temp.value = value << numBits; return temp; }
+	FPTemplate operator>>(int numBits) const { FPTemplate temp; temp.value = value >> numBits; return temp; }
 
 	FPTemplate& operator<<=(int numBits) { value <<= numBits; return *this;}
 	FPTemplate& operator>>=(int numBits) { value >>= numBits; return *this;}

File diff suppressed because it is too large
+ 311 - 1078
source/EASprintfOrdered.cpp


+ 38 - 0
test/source/TestFixedPoint.cpp

@@ -129,6 +129,44 @@ int TestFixedPoint()
 			nErrorCount++;
 	}
 
+	{
+		// FPTemplate operator<<(int numBits) const 
+		{
+			SFixed16 a(16);
+
+			auto expected = a.value << 1;
+
+			a = (a << 1);
+
+			if(!CompareValues(a.value, expected))
+				nErrorCount++;
+		}
+
+		// FPTemplate operator>>(int numBits) const 
+		{
+			SFixed16 a(16);
+
+			auto expected = a.value >> 1;
+
+			a = (a >> 1);
+
+			if(!CompareValues(a.value, expected))
+				nErrorCount++;
+		}
+	}
+
+	// Reported regression - ensure operator<< and operator>> are implemented correctly.
+	{
+		SFixed16 a(16);
+
+		auto expected = a.value;
+
+		a = (a << 1);
+		a = (a >> 1);
+
+		if(!CompareValues(a.value, expected))
+			nErrorCount++;
+	}
 
 	#ifndef EA_DLL
 		// Test SFixed24

Some files were not shown because too many files changed in this diff