Skip to content
fleschutzPublic

About

The physical units library for C++ 17

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

1,148 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📐libSI - The Physical Units Library For C++

CMake on multiple platforms

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: 64-bit FP datatypes, internal calculations on SI base units, and CODATA 2022 constants.
  • Maximum speed without runtime overhead. It just compiles to simple doubles.
  • Supports SI units, Imperial/US units, digital units, astronomical units, and a lot more.
  • Supports implicit scale conversion when mixing different units, e.g. 1_km + 1_m + 1_ft + 1_in.
  • 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.

🔎 Hello, World Example

#include <SI/core>
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;
}

🧱 Building Blocks in <SI/core>

  • Datatypes like SI::length
  • Units such as SI::meters
  • Literals like 100_m
  • Constants such as SI::constant::speed_of_light_in_vacuum
  • Formulas like SI::formula::wavelength()
  • Conversions such as SI::to_string()

🎉 Various

💡 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.

About

The physical units library for C++ 17

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Contributors

Languages