Getting started
This page shows the smallest useful C++ PUQ workflow. Use Concepts and model when you need the underlying quantity semantics, and Workflows when you want to compose the common operations into a larger task.
Construct and convert a quantity
Include the native quantity header, create a value with its unit, and convert it to another compatible unit:
#include <iostream>
#include <snt/puq/quantity.h>
int main() {
snt::puq::Quantity length(2.5, "m");
snt::puq::Quantity length_cm = length.convert("cm");
std::cout << length_cm.to_string() << "\n";
return 0;
}
The original quantity is unchanged. The converted quantity carries the target units and can be formatted, inspected, or used in further dimensional arithmetic.
Build and run
Install the C++ package using Installation with the
PUQ module enabled.
Save the example above as main.cpp and create this CMakeLists.txt in
the same directory:
cmake_minimum_required(VERSION 3.22)
project(snt_puq_example LANGUAGES C CXX)
find_package(snt CONFIG REQUIRED)
add_executable(application main.cpp)
target_compile_features(application PRIVATE cxx_std_17)
target_link_libraries(application PRIVATE snt-puq)
Configure with the installed package prefix, build, and run:
cmake -S . -B build -DCMAKE_PREFIX_PATH=/path/to/snt
cmake --build build
./build/application
Expected output:
250*cm
Replace /path/to/snt with the installation prefix; omit that option if
CMake already finds SNT. C is enabled for discovery of HDF5 in packages built
with DIP support. See Using SciNumTools from CMake for package discovery details.
Continue with
Concepts and model explains quantities, dimensions, arithmetic, arrays, and uncertainty.
Workflows shows calculation, conversion, and composition tasks.
PUEL calculation and Conversion and unit systems cover the detailed topic pages.
PUQ interfaces lists the Python, C ABI, Rust, WebAssembly/JavaScript, and command-line counterparts.