Skip to content
/ mlr Public

mlr - single-header-only C++ linear algebra math library

License

Notifications You must be signed in to change notification settings

jopadan/mlr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mlr

mlr - single-header-only C++26 linear algebra math library

About

mlr implements aligned array arr : std::array<T,N> based vector vec::type<T,N,A> type for N-dimensional linear algebra math using OpenGL/KHR and Quake scalar types

Dependencies

Building

cmake . --install-prefix=/usr
make install

Optimization

Change CMakeLists.txt compile flags to fit your needs:

add_compile_options(-march=native -mfpmath=[your SIMD instruction set] -O3)

Usage

#include <mlr/vector.hpp>

using namespace math;

bool test_cross()
{
	vec::f64<4> src[4] = { vec::f64<4>::identity(0),
	                       vec::f64<4>::identity(1),
			       vec::f64<4>::load3(vec::f64<3, align::vector>::cross3(src[0],src[1]).data(),0),
			       vec::f64<2>::cross4(src[0],src[1],src[2]) };

	vec::f64<2>   a[2] = { vec::f64<2>::cross2(src[0], GL_CCW), vec::f64<2>::cross2(src[0], GL_CW) };

	a[0].print_header(4,"test_cross2");
	a[0].print(4);
	src[2].print(4);
	src[3].print(4);
	return true;
}

bool test_dot()
{
	vec::f64<4> a = {1,2,3,4};
	vec::u64<4> b = {5,6,7,8};
	vec::i64<4> c = {9,10,11,12};
	vec::i32<4> d = {13,14,15,16};
	printf("%-39s\n", "test_dot4");
	printf("%f\n",vec::f64<4>::dot4(a,b,c,d));
	return true;
}

int main(int argc, char** argv)
{
	test_cross();
	vec::f32<4> d = { 5,6,7,8 };
	vec::f32<4, align::scalar> c = { 1,2,3,4 };
	vec::f32<3> a = { 5,6,7 };
	vec::f32<3, align::vector> b = { 1,2,3 };
	a+=b;
	b+=a;
	a.print();
	b.print();
	d.print();
	c.print();
	printf("\n");
	test_dot();
	printf("\n");
	exit(EXIT_SUCCESS);
}
|test_cross2                            | typ|alg|vec|alg|mode           |cnt
|-0.00e+00 +1.00e+00 +0.00e+00 -1.00e+00|   8|  8| 16| 16|adaptive/vector|2
|+0.00e+00 +0.00e+00 +1.00e+00 +0.00e+00|   8|  8| 32| 32|adaptive/vector|4
|-0.00e+00 +0.00e+00 -0.00e+00 +1.00e+00|   8|  8| 32| 32|adaptive/vector|4
|+6.00e+00 +8.00e+00 +1.00e+01 +4.56e-41|   4|  4| 12|  4|adaptive/scalar|3
|+7.00e+00 +1.00e+01 +1.30e+01 +4.56e-41|   4|  4| 16| 16|         vector|3
|+5.00e+00 +6.00e+00 +7.00e+00 +8.00e+00|   4|  4| 16| 16|adaptive/vector|4
|+1.00e+00 +2.00e+00 +3.00e+00 +4.00e+00|   4|  4| 16|  4|         scalar|4

test_dot4                              
11874.000000

Links

Other C++ Math Libraries

Quake C++ Math Libraries

War for the Overworld C++ Math Library

Math code/tutorials