Browse Source

Implemented unary negation for FixedPoint.

David Piuva 3 years ago
parent
commit
0dfd8523b1
2 changed files with 4 additions and 1 deletions
  1. 1 1
      Source/DFPSR/math/FixedPoint.cpp
  2. 3 0
      Source/DFPSR/math/FixedPoint.h

+ 1 - 1
Source/DFPSR/math/FixedPoint.cpp

@@ -316,7 +316,7 @@ double dsr::fixedPoint_approximate(const FixedPoint& value) {
 }
 
 String& dsr::string_toStreamIndented(String& target, const FixedPoint& value, const ReadableString& indentation) {
-	// TODO: Make own fixed-point serialization which cannot resort to scientific notation
+	// TODO: Make a deterministic fixed-point serialization
 	string_append(target, indentation, fixedPoint_approximate(value));
 	return target;
 }

+ 3 - 0
Source/DFPSR/math/FixedPoint.h

@@ -85,6 +85,9 @@ inline FixedPoint operator-(const FixedPoint &left, int32_t right) {
 inline FixedPoint operator-(int32_t left, const FixedPoint &right) {
 	return FixedPoint((left * 65536) - right.getMantissa());
 }
+inline FixedPoint operator-(const FixedPoint& value) {
+	return FixedPoint(0 - value.getMantissa());
+}
 
 // Multiplication is faster against whole integers, by not having to reduce the result
 inline FixedPoint operator*(const FixedPoint &left, const FixedPoint &right) {