Small updates

This commit is contained in:
Erik Hofman 2016-11-20 14:59:43 +01:00
parent 73f57bbbd8
commit ad6f3d2db2

View File

@ -6,16 +6,33 @@
#include "SGVec3.hxx"
#include "SGVec4.hxx"
#define TEST(a, p,q,r,s) \
if (a[0] != p || a[1] != q || a[2] != r || a[3] != s) \
printf("line: %i, diff: %5.4e, %5.4e, %5.4e, %5.4e\n", __LINE__, fabsf(a[0]-p), fabsf(a[1]-q), fabsf(a[2]-r), fabsf(a[3]-s));
// set to 0 for a timing test
#define TEST_ACCURACY 1
#if TEST_ACCURACY
# define TEST(a, p,q,r,s) \
if (a[0] != (p) || a[1] != (q) || a[2] != (r) || a[3] != (s)) \
printf("line: %i, diff: %5.4e, %5.4e, %5.4e, %5.4e\n", __LINE__, fabsf(a[0]-(p)), fabsf(a[1]-(q)), fabsf(a[2]-(r)), fabsf(a[3]-(s)));
# define MAX 1
#else
# define TEST(a, p,q,r,s)
# define MAX 1000000
#endif
#define T double
int main()
{
float p[4] = { 1.03f, 0.55f, 0.707f, -0.01f };
const SGVec4f q( 0.31, 0.43, 0.69, 1.0 );
SGVec4<float> v(p), x(p), y(p);
float f, g;
T p[4] = { 1.03, 0.55, 0.707, -0.01 };
const SGVec4<T> q( 0.31, 0.43, 0.69, 1.0 );
long int i;
for (i=0; i<MAX; i++)
{
SGVec4<T> v(p);
SGVec4<T> x(v), y(v);
T f, g;
TEST(x, p[0], p[1], p[2], p[3]);
@ -25,11 +42,11 @@ int main()
y -= q;
TEST(y, p[0]-q[0], p[1]-q[1], p[2]-q[2], p[3]-q[3]);
v = x; x *= 1.7f;
TEST(x, v[0]*1.7f, v[1]*1.7f, v[2]*1.7f, v[3]*1.7f);
v = x; x *= 1.7;
TEST(x, v[0]*1.7, v[1]*1.7, v[2]*1.7, v[3]*1.7);
v = y; y /= -.3f;
TEST(y, v[0]/-.3f, v[1]/-.3f, v[2]/-.3f, v[3]/-.3f);
v = y; y /= -.3;
TEST(y, v[0]/-.3, v[1]/-.3, v[2]/-.3, v[3]/-.3);
v = +x;
TEST(v, x[0], x[1], x[2], x[3]);
@ -40,11 +57,11 @@ int main()
v = y+x;
TEST(v, y[0]+x[0], y[1]+x[1], y[2]+x[2], y[3]+x[3]);
y = v*1.7f;
TEST(y, v[0]*1.7f, v[1]*1.7f, v[2]*1.7f, v[3]*1.7f);
y = v*1.7;
TEST(y, v[0]*1.7, v[1]*1.7, v[2]*1.7, v[3]*1.7);
y = 1.7f*v;
TEST(y, v[0]*1.7f, v[1]*1.7f, v[2]*1.7f, v[3]*1.7f);
y = 1.7*v;
TEST(y, v[0]*1.7, v[1]*1.7, v[2]*1.7, v[3]*1.7);
v = y-x;
TEST(v, y[0]-x[0], y[1]-x[1], y[2]-x[2], y[3]-x[3]);
@ -62,10 +79,11 @@ int main()
}
x = v; v -= y;
SGVec4<float> t = x - y;
SGVec4<T> t = x - y;
f = dot(v, v);
g = (t[0]*t[0] + t[1]*t[1] + t[2]*t[2] + t[3]*t[3]);
if (f != g) {
printf("line: %i: dot: f: %5.4f, g: %5.4f\n", __LINE__, f, g);
}
}
}