From: Sam Moore <matches@ucc.asn.au>
Date: Sun, 3 Aug 2014 13:55:56 +0000 (+0800)
Subject: Remove terrible "pow()" functions
X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=9e1a33043e1242c4605f2a3a48bd948fc760d948;p=ipdf%2Fcode.git

Remove terrible "pow()" functions

There are many reasons why that was terrible and it finally all came apart
in a segfaultastic display.

We now have Power which only works for integer powers
But we only need those at the moment anyway.
---

diff --git a/src/bezier.cpp b/src/bezier.cpp
index 15a5069..c71d0a9 100644
--- a/src/bezier.cpp
+++ b/src/bezier.cpp
@@ -42,7 +42,7 @@ int BinomialCoeff(int n, int k)
  */
 Real Bernstein(int k, int n, const Real & u)
 {
-	return Real(BinomialCoeff(n, k)) * pow(u, k) * pow(Real(1.0) - u, n-k);
+	return Real(BinomialCoeff(n, k)) * Power(u, k) * Power(Real(1.0) - u, n-k);
 }
 
 }
diff --git a/src/rational.h b/src/rational.h
index 6bc5aec..595f5f2 100644
--- a/src/rational.h
+++ b/src/rational.h
@@ -196,13 +196,6 @@ struct Rational
 	T Q;
 };
 
-inline Rational<int64_t> pow(const Rational<int64_t> & a, const Rational<int64_t> & b)
-{
-	//TODO:Implement properly
-	int64_t P = std::pow((double)a.P, b.ToDouble());
-	int64_t Q = std::pow((double)a.Q, b.ToDouble());
-	return Rational<int64_t>(P, Q);
-}
 
 
 
diff --git a/src/real.cpp b/src/real.cpp
index 96d8054..0f104e5 100644
--- a/src/real.cpp
+++ b/src/real.cpp
@@ -7,7 +7,7 @@ namespace IPDF
 		"single",
 		"double",
 		"long double",
-		"single [fast2sum]", //TODO REMOVE DOESN'T DO ANYTHING USEFUL
+		"VFPU",
 		"Rational<int64_t>", 
 		"Rational<Arbint>"
 	};
diff --git a/src/real.h b/src/real.h
index 4b2db1c..d8033fc 100644
--- a/src/real.h
+++ b/src/real.h
@@ -54,12 +54,7 @@ namespace IPDF
 	typedef Rational<ARBINT> Real;
 	inline float Float(const Real & r) {return (float)r.ToDouble();}
 	inline double Double(const Real & r) {return r.ToDouble();}
-	inline Rational<ARBINT> pow(const Rational<ARBINT> & a, const Rational<ARBINT> & b)
-	{
-		ARBINT P(std::pow(static_cast<double>(a.P), b.ToDouble()));
-		ARBINT Q(std::pow(static_cast<double>(a.Q), b.ToDouble()));
-		return Rational<ARBINT>(P,Q);
-	}
+
 #else
 	#error "Type of Real unspecified."
 #endif //REAL
@@ -73,6 +68,19 @@ namespace IPDF
 	inline double Double(float f) {return (double)f;}
 	inline double Double(double f) {return (double)f;}
 	inline double Double(long double f) {return (double)(f);}
+	
+	inline Real Power(const Real & a, int n)
+	{
+		if (n < 0)
+		{
+			return Power(Real(1)/a, -n);
+		}
+		Real r(1);
+		for (int i = 0; i < n; ++i)
+			r *= a;
+		return r;
+	}
+	
 }
 
 #endif //_REAL_H
diff --git a/src/vfpu.h b/src/vfpu.h
index a2102f9..8444afd 100644
--- a/src/vfpu.h
+++ b/src/vfpu.h
@@ -86,11 +86,6 @@ namespace VFPU
 			float m_value;
 			
 	};
-	
-	inline Float pow(const Float & a, const Float & b)
-	{
-		return Float(pow(a.m_value, b.m_value));
-	}
 }
 
 #endif //_VFPU_H
diff --git a/src/view.cpp b/src/view.cpp
index 1fe0728..54e4155 100644
--- a/src/view.cpp
+++ b/src/view.cpp
@@ -183,7 +183,7 @@ void View::RenderQuadtreeNode(int width, int height, QuadTreeIndex node, int rem
 	Rect old_bounds = m_bounds;
 	if (node == QUADTREE_EMPTY) return;
 	if (!remaining_depth) return;
-	Debug("Rendering QT node %d, (objs: %d -- %d)\n", node, m_document.GetQuadTree().nodes[node].object_begin, m_document.GetQuadTree().nodes[node].object_end);
+	//Debug("Rendering QT node %d, (objs: %d -- %d)\n", node, m_document.GetQuadTree().nodes[node].object_begin, m_document.GetQuadTree().nodes[node].object_end);
 	RenderRange(width, height, m_document.GetQuadTree().nodes[node].object_begin, m_document.GetQuadTree().nodes[node].object_end);
 
 	m_bounds = TransformToQuadChild(old_bounds, QTC_TOP_LEFT);