
Use libSI to apply math in C++ correct, precise, and convenient. Top features are:
- Strong type-safety for datatypes, constants, formulas, and literals (can't add a mass to a length).
- High precision by FP 64-bit, calculations on SI base units only, and CODATA 2022 constants.
- Maximum speed without runtime overhead. It just compiles to simple doubles.
- Supports SI units, Imperial units, digital units, astronomical units, and a lot more.
- Modern C++ 17: header-only, own namespace, no external dependencies.
- Cross-platform support for Linux (clang/gcc, x86/arm) and Windows (VS2017-VS2026) with CMake support.
🔎 Usage Example
mass m = 1_oz;
energy E = m *
square(constant::speed_of_light_in_vacuum);
std::cout << "The potential energy of a single ounce is: " << E << std::endl;
}
Includes the 6 core header files (for convenience).
int main()
Definition main.cpp:11
Definition constants.h:12
SI_INLINE_CONSTEXPR auto square(T x)
Raise any number <x> to power of 2 (x² or x*x).
Definition units.h:193
🧱 Core Building Blocks
📦 Other Components
💡 Q & A
What is SI? It's the International System of Units which is made up of 7 base units that define the 22 derived units.
What is CODATA? It's the Committee On Data of the International Science Council (ISC). It publishes fundamental physical constants on a four-year cycle. Latest update was CODATA 2022 which is equal to: NIST SP 961 (May 2024).
What are use-cases for libSI? Applied math such as simulations, simulators, scientific calculations, games, etc.
What are numbers like 1.2e23? It's the scientific notation in C/C++ for 1.2 x 10²³, the letter 'e' or 'E' represents the 'times 10 to the power of' part.
How to import or export numbers and string? See the code examples in examples/conversions.cpp.
Where are the list of references? References are always listed at the end of each source code file.
🤝 Contributing
- Contributions, suggestions, and improvements are welcome!
- Open an Issue if you encounter bugs or have feature ideas.
- Create a Pull Request if you'd like to improve something.
📜 License & Copyright
This open source project is licensed under the CC0-1.0 license. All trademarks are the property of their respective owners.