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.
#include <SI/core.h>
using namespace SI;
int main() {
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;
}- Datatypes like SI::length in <SI/datatypes.h>
- Units such as SI::meters in <SI/units.h>
- Literals like 100_m in <SI/literals.h>
- Constants such as SI::constant::lightyear in <SI/constants.h>
- Formulas like SI::formula::wavelength() in <SI/formulas.h>
- Conversions such as SI::to_string() in <SI/conversions.h>
- 47 Examples writing this console output in subfolder 📂examples
- Unit tests executed at compile-time and on each commit by GitHub Actions in <SI/tests.h>
- Datasets like chemical_elements in 📂datasets (using libSI datatypes and units)
- Documentation in the API reference manual
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.
- 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.
This open source project is licensed under the CC0-1.0 license. All trademarks are the property of their respective owners.