r/cprogramming • u/alkavan • Sep 20 '26
Vecmat: A simple, yet robust, linear algebra library in C — for graphics, physics, games, and simulations
I built it mainly for myself (and my needs), and out of great love for the C language. It's already successfully battle-tested building an 2D/3D SDL3 graphics engine with the library as math backbone (will publish by the end of this year).
It's called Vecmat: https://github.com/alkavan/vecmat
The main goals are:
- One common, easy-to-read API that is self-explanatory.
- Usability first, then performance.
Having said, it features a special runtime dispatch mechanism that an inner kernel may use AVX / AVX2 / AVX-512 / SVE / SVE2, otherwise scalar (cascading manner). So it's already extremely fast, and offers also a pointer-only API instead of copy interfaces (that most of the time use the pointer API behind the scenes).
It's under BSD 3-Clause license and comes with a simple unit testing and benchmarking framework.
It needs some more love, because you can do amazing things with it. It's super easy to integrate into projects because it has zero dependencies except the system math lib.
I might implement NEON support soon, because it actually became a business need of mine, and I'll surely do it if people would ask for it.
It took me a whole year to build it, and while AI was involved in documenting, system integration, and some of the complex math algorithms (it has a few), building this library required a tremendous amount of human labor and review.
Hope you like it!
3
u/zhivago Sep 20 '26
Very nice -- at a glance I don't see anything objectionable. :)
3
u/tastygames_official Sep 20 '26
for my SDL3 3D application (game) I'm using cglm (C OpenGL Math) library, which is optimized for performance and so far I'm happy with it. You say you optimized yours for usability. Can you give me an example? Or try to "sell" me your library? I generally prefer performance over "usability", but all things else equal, I'll prefer better naming conventions, and I already like yours (cglm's are all glm_xxx() and I don't like that)
2
u/Kale Sep 20 '26
Runtime selection of vector intrinsics? Wow. I'm impressed.
Thanks for open sourcing this. This is both useful to people who need the math, and people like me who need to see completed projects to learn HPC and intrinsics.
1
u/Interesting_Debate57 Sep 20 '26
"some of the complex math operations" -- how do you know it got these correct?