Skip to the content.

libSI - The C++ Lib of Type-safe SI Units

A units library to apply math with physical units correct, convenient and with high precision.

CMake on multiple platforms

🧱 Building Blocks

  1. Datatypes such as SI::length or SI::time in SI/datatypes.h
  2. Units such as SI::meters or SI::seconds in SI/units.h
  3. Literals such as 100_m or 60_s in SI/literals.h
  4. Constants such as SI::constant::speed_of_light in SI/constants.h
  5. Formulas such as SI::formula::wavelength() in SI/formulas.h
  6. Conversions in SI/from_string.h, SI/to_string.h, and in SI/to_equivalent.h
  7. Tests at compile-time in SI/unit_tests.h and on each commit by GitHub Actions
  8. Datasets such as chemical elements in 📂datasets

🔎 Quick Example

#include <SI/all.h>
using namespace SI;

int main() {	
    mass m = 1_oz;
    velocity c = constant::speed_of_light;
    energy E = m * c * c;
    println("The potential energy of a single ounce is: ", E);
}

Executing: cmake . && make && ./examples writes to the console:

The potential energy of a single ounce is: 2.55PJ

42 further examples can be found at: examples.cpp, producing this output: console output.

💡 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, astronomy/physics 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? Import double x = 42; with length dist = x * 1_m; and export with double y = dist / 1_m;.

How to import or export strings? Import with from_string("42m", dist) and export with std::string str = to_string(dist);

Where are the list of references? References are always listed at the end of each source code file.

🤝 Contributing

This open source project is licensed under the CC0-1.0 license. All trademarks are the property of their respective owners.