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

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mlr

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

About

MLR implements aligned fixed_valarray : std::array<T,N> vector math using OpenGL/KHR 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/mlr.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) };

	printf("%-39s: %3s/%3s/%3s/%3s\n", "test_cross", "typ", "cnt", "alg", "len");
	printf("%+8f %+8f %+8f %+8f: %3zu/%3zu/%3zu/%3zu\n", a[0][0], a[0][1], a[1][0], a[1][1], sizeof(f64), a[0].size(), alignof(a[0]), sizeof(a[0]));
	printf("%+8f %+8f %+8f %+8f: %3zu/%3zu/%3zu/%3zu\n", src[2][0], src[2][1], src[2][2], src[2][3], sizeof(f64), (size_t)3, alignof(src[2]), sizeof(src[2]));
	printf("%+8f %+8f %+8f %+8f: %3zu/%3zu/%3zu/%3zu\n", src[3][0], src[3][1], src[3][2], src[3][3], sizeof(f64), src[3].size(), alignof(src[3]), sizeof(src[3]));
	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("%f\n",vec::f64<4>::dot4(a,b,c,d));
	return true;
}
test_cross2        : typ/cnt/alg/len
+1.000000 +0.000000:   8/  2/ 16/ 16
-0.000000 +1.000000:   8/  2/  8/ 16
+0.000000 -1.000000:   8/  2/ 16/ 16

test_cross3                            : typ/cnt/alg/len
+1.000000 +0.000000 +0.000000 +0.000000:   8/  4/ 32/ 32
+0.000000 +1.000000 +0.000000 -0.000000:   8/  3/  8/ 24
+0.000000 +0.000000 +1.000000 -0.000000:   8/  3/ 32/ 32
+0.000000 +1.000000 +1.000000 -0.000000:   8/  4/  8/ 32


test_cross2                            : typ/cnt/alg/len
-0.000000 +1.000000 +0.000000 -1.000000:   8/  2/ 16/ 16
test_cross3                            : typ/cnt/alg/len
+0.000000 +0.000000 +1.000000 +0.000000:   8/  3/ 32/ 32
test_cross4                            : typ/cnt/alg/len
-0.000000 +0.000000 -0.000000 +1.000000:   8/  4/ 32/ 32

test_dot4                              
11874.000000

Links

Other C++ Math Libraries

Quake C++ Math Libraries

War for the Overworld C++ Math Library

Math code/tutorials

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published