Skip to content

Math library

Phawit Pornwattanakul edited this page Sep 17, 2025 · 2 revisions

In Sakura we have our own implementation of the math library.

In this project's dependency, we have 2 math library that we based on

For the performance, the System.Numerics has done a better job based on the Hardware Intrinsics type support so I decided to create our own implementation based on these 2 libraries since we can't throw the Silk.NET's math library of due to all binding in Silk.NET required the type from this library.

Another reason is from this discussion

How the type work

The math class reside in Sakura.Framework.Maths namespace. In each struct the structure is the same

  • Original System.Numerics type to store the real value (We call this Value in the code)
  • Basic value binding to the real value (e.g. Vector2 have X and Y)
  • Implicit type conversion between Sakura.Framework.Maths, System.Numerics and Silk.NET.Maths

Note that all of the struct marked as partial and have MathStruct attribute for the source generator that will generate the method used in that class based on the method in System.Numerics.

See Source Generator > Math struct for more info on the source generator.

Clone this wiki locally