Skip to content
fleschutzPublic

Latest commit

 

History

1,491 Commits

Folders and files

Repository files navigation

📐si-lib - The Physical Units Library For C++

CMake on multiple platforms

Include si-lib to apply math in C++ correct, precise, and convenient. Features are:

  • Type-safety for datatypes, constants, formulas, literals, etc. (e.g. mass + length = error).
  • Test-safety by 300+ unit tests (executed at compile-time and on each commit).
  • Top precision: 64-bit floating point, calculations on SI base units only, and CODATA 2022 constants.
  • Full speed: no runtime overhead and implicit compile-time conversions.
  • Support for units in SI, Imperial, US, digital, astronomical, historic, or user-defined.
  • Excellent readability - with bundled literals, constants, formulas, and datasets (optional).
  • Modern C++ 17: header-only, light-weight (143KB), own namespace, no external dependencies.
  • Cross-platform support for Linux (clang/gcc, x86/arm) and Windows (VS2017-VS2026).

🔎 Example

#include <si/core.h>

int main() {   using namespace si;
    mass m   = 1_kg;
    energy E = m * constant::c²;
    std::cout << "The potential energy per kilogram is: " << E << std::endl;
}

🧱 Building Blocks

Example Location
Namespace si (in all header files)
Datatypes mass <si/datatypes.h>
Units kilograms <si/units.h>
User-defined literals 1_kg <si/literals.h>
Constants constant::c (the speed of light) <si/constants.h>
Formulas hypotenuse_formula() <si/formulas.h>
Conversions to_string() <si/conversions.h>
Unit tests static_assert(1_kg == 1000_g); <si/tests.h>
Examples speeds.cpp & program output 📂examples
Datasets Earth.mass 📂examples/datasets
Documentation cheat_sheet.cpp 📓API Reference

💡 Q & A

Why si-lib? Programming with quantities (=a number and a unit) is more safe, more readable, and more intuitive.

What are si-lib's use-cases? Applied math in simulations, simulators, scientific calculations, games, etc.

How to use si-lib? Just follow the integration manual.

Is it thread-safe? Yes, the datatypes are trivially-copyable value types without shared state. The library's errors are at compile-time only and no exceptions are thrown.

What's SI? It's the International System of Units which is made up of 7 base units that define the 22 derived units.

What's 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.

What's IAU? It's the International Astronomical Union, which defines the astronomical units.

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.

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.

Releases

Sponsor this project

Contributors

Languages

⌂ 换网址