Loading repository data…
Loading repository data…
MrUnbelievable92 / repository
A successor to the SIMD math library Unity.Mathematics, extending it to all C# numeric types while adding many new types and functions. Written entirely with hardware intrinsics, using Unity.Burst.
MaxMath is the most powerful and extensive SIMD math library available to Unity developers. Built on top of Unity.Mathematics and utilizing Unity.Burst, it introduces the following key features:
(s)byte, (u)short, and (u)long vectors and matrices. These data types come with specialized overloads for all functions in Unity.Mathematics. Additionally, specialized Random8/16/32/64/128 types are available for efficient pseudo-random number generation.byte32, short16, int8, and float8. This allows you to leverage the full potential of SIMD computation.(U)Int128 (scalar only), 128-bit quadruple precision floats (scalar only), and 8-bit quarter precision floats (in both scalar and vector forms). Additionally, Divider<T> offers highly optimized integer division operations, extending and outperforming specialized libraries like libdivide.Unity.Burst.CompilerServices.Constant.IsConstantExpression<T>() to include code typically only found in optimizing compilers. This functionality allows MaxMath to choose more optimized code paths at compile time, and users can influence this behavior via the optional Promise enum parameter available in many functions. MaxMath also systematically annotates virtually every operation with rich semantic postconditions communicated direcly to Burst via Unity.Burst.CompilerServices.Hint.Assume(), preserving mathematical and bit-level properties across opaque implementations so LLVM can continue propagating optimization opportunities beyond abstraction boundaries.implicit and explicit type conversions, making it seamless for you to use if you expect typical C# behavior of primitive types.DEBUG only runtime checks where appropriate, together ensuring it is production ready.Prior to version 3.0, MaxMath served as a supplementary library to Unity.Mathematics. Starting with 3.0, it is a drop-in replacement/wrapper for Unity.Mathematics, fully compatible while extending it with additional MaxMath functionality. Because MaxMath had been developed as an extension library for several years, this architectural change was among the most difficult design decisions in the project's history. Nevertheless, it ultimately became clear that a wrapper architecture was necessary for the following reasons:
MaxMath builds on Unity.Mathematics with additional functionality and numerous performance improvements (See the 3.0 patch notes for the changes). Several bugs in Unity.Mathematics have not been fixed for multiple years, particularly with regards to half.
MaxMath is actively maintained, with recent releases and public GitHub Issues/Discussions for feedback. By comparison, Unity.Mathematics still shows a substantial amount of open issues and feature requests in its public repository, and its README notes that pull requests are not accepted.
Given its development history, it appears unlikely that Unity.Mathematics will take advantage of the Unity ecosystem's migration to the CoreCLR scripting runtime and the direct access to hardware intrinsics this enables. Instead, it relies entirely on Burst's compiler recognition of its types and functions for SIMD code generation rather than explicit hardware intrinsics within the library itself, limiting its long-term potential for managed C# performance. Likewise, it is unlikely to adopt newer C# language features, such as the generalized shift operators introduced in C# 11, where the shift count is no longer restricted to int.
Finally, consolidating Unity.Mathematics and MaxMath into a single API eliminates the need to reference and mentally distinguish between two separate math libraries. Requiring both using Unity.Mathematics; (or using static Unity.Mathematics.math;) and using MaxMath; (or using static MaxMath.maxmath;) was unnecessarily verbose and fragmented the user experience. A unified API is both more elegant and more intuitive to use.



















Note: The function signatures (but not their names), parameter names, and descriptions shown below have been intentionally simplified to keep this catalog concise and easy to browse. They do not reflect the naming conventions or XML documentation used throughout MaxMath, which provide substantially more descriptive parameter names, detailed explanations, and full IntelliSense support in IDEs (see the example below).
This section is intended solely as a high-level overview of the available functionality rather than a replacement for the library's built-in documentation.
In addition, many functions have an optional enum Promise parameter for optimized code paths not listed here.
Each operation is available for all applicable scalar, vector, and matrix types.
An example for XML documentation used in MaxMath:
