From: Sam Moore Date: Fri, 4 Jul 2014 05:09:47 +0000 (+0800) Subject: Moronic bug identified, also Backtrace is a thing now X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=e7e4a7ad5c977ae089bab7081e7931fd5e423cc1;p=ipdf%2Fcode.git Moronic bug identified, also Backtrace is a thing now Copy/Paste bug @rational.h:123 At least division and addition both involve maths right? --- diff --git a/.gitignore b/.gitignore index 5041ffa..28b8762 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,8 @@ *.err *.vcd *.bmp +*.data +*.geany +*.dat +bin/ipdf +data/* diff --git a/bin/ipdf b/bin/ipdf deleted file mode 100755 index 03e79d7..0000000 Binary files a/bin/ipdf and /dev/null differ diff --git a/src/Makefile b/src/Makefile index 8ff6370..a26843f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,7 @@ #Makefile ARCH := $(shell uname -m) # TODO: stb_truetype doesn't compile with some of these warnings. -CXX = g++ -std=gnu++0x -g -Wall -Werror -Wshadow -pedantic +CXX = g++ -std=gnu++0x -g -Wall -Werror -Wshadow -pedantic -rdynamic MAIN = main.o OBJ = log.o real.o bezier.o document.o objectrenderer.o view.o screen.o vfpu.o graphicsbuffer.o framebuffer.o shaderprogram.o stb_truetype.o gl_core44.o LIB_x86_64 = ../contrib/lib/libSDL2-2.0.so.0 -lGL diff --git a/src/log.cpp b/src/log.cpp index 3af4aca..49b209a 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #ifdef LOG_SYSLOG @@ -139,3 +140,13 @@ void FatalEx(const char * funct, const char * file, int line, ...) } +/** + * Print a backtrace + */ +void Backtrace(int size) +{ + void * buffer[100]; + int actual_size = backtrace(buffer, size); + backtrace_symbols_fd(buffer, actual_size, fileno(stderr)); +} + diff --git a/src/log.h b/src/log.h index fdf30a7..d49c149 100644 --- a/src/log.h +++ b/src/log.h @@ -37,6 +37,7 @@ inline std::string methodName(const std::string& prettyFunction) #define Debug(...) LogEx(LOG_DEBUG, __func__, __FILE__, __LINE__, __VA_ARGS__) #define Error(...) LogEx(LOG_ERR, __func__, __FILE__, __LINE__, __VA_ARGS__) #define Warn(...) LogEx(LOG_WARNING, __func__, __FILE__, __LINE__, __VA_ARGS__) +extern void Backtrace(int size=10); extern void LogEx(int level, const char * funct, const char * file, int line, ...); // General function for printing log messages to stderr diff --git a/src/rational.h b/src/rational.h index b3709ad..c2215a0 100644 --- a/src/rational.h +++ b/src/rational.h @@ -12,8 +12,7 @@ namespace IPDF { -/** Greatest Common Divisor - Euclid's algorithm **/ - +/* Recursive version of GCD template T gcd(const T & a, const T & b) { @@ -24,12 +23,12 @@ T gcd(const T & a, const T & b) if (a > b) return gcd(a-b,b); return gcd(a, b-a); } +*/ -/* +/** Greatest Common Divisor of p and q **/ template T gcd(const T & p, const T & q) { - Debug("p/q = % T g(1); T big(p); T small(q); @@ -47,15 +46,15 @@ T gcd(const T & p, const T & q) } return small; } -*/ + template struct Rational { /** Construct from a double.**/ - Rational(double d = 0) : P(d*1e3), Q(1e3) // Possibly the worst thing ever... + Rational(double d = 0) : P(d*1e6), Q(1e6) // Possibly the worst thing ever... { Simplify(); - //CheckAccuracy(d, "Construct from double"); + CheckAccuracy(d, "Construct from double"); } Rational(const T & _P, const T & _Q) : P(_P), Q(_Q) @@ -121,8 +120,8 @@ struct Rational } Rational operator/(const Rational & r) const { - Rational result = (r.P == 0) ? Rational(P,Q) : Rational(P*r.Q + r.P*Q, Q*r.Q); - if (!result.CheckAccuracy(ToDouble() / r.ToDouble(),"*")) + Rational result(P * r.Q, Q*r.P); + if (!result.CheckAccuracy(ToDouble() / r.ToDouble(),"/")) { Debug("This is %s (%f) and r is %s (%f)", Str().c_str(), ToDouble(), r.Str().c_str(), r.ToDouble()); } @@ -141,7 +140,7 @@ struct Rational Rational & operator/=(const Rational & r) {this->operator=(*this/r); return *this;} double ToDouble() const {return (double)(P) / (double)(Q);} - bool CheckAccuracy(double d, const char * msg, double threshold = 1e-6) const + bool CheckAccuracy(double d, const char * msg, double threshold = 1e-3) const { double result = fabs(ToDouble() - d) / d; if (result > threshold)