Mathematics and formatting

Mathematical operations, quantity formatting, and display utilities.

std::string snt::puq::to_string(const puq::Result &value, int precision = static_cast<int>(std::cout.precision()))

Format a PUQ result.

std::string snt::puq::to_string(const puq::BaseUnits &value, int precision = static_cast<int>(std::cout.precision()))

Format a base-unit expression.

std::string snt::puq::to_string(const puq::Dimensions &value, const puq::UnitFormat &format = puq::UnitFormat())

Format dimensions using unit-format options.

std::string snt::puq::to_string(const puq::ExponentVariant &value, const puq::UnitFormat &format = puq::UnitFormat())

Format an exponent using unit-format options.

std::string snt::puq::to_string(const bool &use_prefixes, const puq::AllowedPrefixes &value)

Format an allowed-prefix map.

template<typename T, typename ...Args>
std::optional<T> snt::puq::get_option(const Args&... args)
static size_t snt::puq::display_length(const std::string &str)

Return the display width of a UTF-8 string in characters.

class DataTable
#include <data_table.h>

Lightweight text table formatter used in diagnostics and output.

Public Functions

inline DataTable(std::vector<DataTableStruct> s)
inline void append(std::vector<std::string> columns)

Append an item to the collection.

Parameters:

columns – Column names to append.

inline std::string to_string()
inline std::string to_json()
struct DataTableStruct
#include <data_table.h>

One row or column definition used by a formatted data table.

Public Members

std::string title
int width
class UnitFormat
#include <unit_format.h>

Formatting options for quantities, units, arrays, and uncertainties.

Public Functions

template<typename ...Args>
inline UnitFormat(const Args&... args)
template<typename ...Args>
inline UnitFormat merge(const Args&... args) const
std::string multiply_symbol() const
std::string format_exponents(std::string expression) const
std::string format_order(std::string expression) const
std::string format_system(std::string expression, const std::string &abbrev) const
bool display_result() const
bool display_units() const
bool display_uncertainty() const

Public Members

Format::System system
Format::Precision precision
Format::Math math
Format::Display part
Format::Base base
Format::Uncertainty uncertainty

Public Static Functions

static bool preprocess_system(std::string &expression, const std::string &abbrev)
static void preprocess_symbols(std::string &expression)
enum class snt::puq::Format::System

Values:

enumerator SHOW
enumerator HIDE
enum class snt::puq::Format::Math

Values:

enumerator ASCII
enumerator UNICODE
enumerator HTML
enumerator MATH
enum class snt::puq::Format::Display

Values:

enumerator BOTH
enumerator RESULT
enumerator UNITS
enum class snt::puq::Format::Base

Values:

enumerator UNITS
enumerator MGS
enumerator MKS
enumerator CGS
enumerator FPS
enum class snt::puq::Format::Uncertainty

Values:

enumerator SHOW
enumerator HIDE
using snt::puq::Format::Precision = int
puq::Result snt::puq::math::abs(const puq::Result &res)

Return the absolute value of a PUQ result.

puq::Measurement snt::puq::math::abs(const puq::Measurement &msr)

Return the absolute value of a PUQ measurement.

puq::Quantity snt::puq::math::abs(const puq::Quantity &quant)

Return the absolute value of a PUQ quantity.

puq::BaseUnits snt::puq::math::cbrt(const puq::BaseUnits &bu)

Apply the cbrt operation to this operand.

Parameters:

bu – Base-unit expression whose exponents are transformed.

puq::Result snt::puq::math::cbrt(const puq::Result &res)

Apply the cbrt operation to this operand.

Parameters:

res – Result whose estimate and uncertainty are transformed.

puq::Measurement snt::puq::math::cbrt(const puq::Measurement &msr)

Apply the cbrt operation to this operand.

Parameters:

msr – Measurement whose value and uncertainty are transformed.

puq::Quantity snt::puq::math::cbrt(const puq::Quantity &quant)

Apply the cbrt operation to this operand.

Parameters:

quant – Quantity whose value and uncertainty are transformed.

puq::Result snt::puq::math::ceil(const puq::Result &res)

Apply the ceil operation to this operand.

Parameters:

res – Result whose estimate and uncertainty are transformed.

puq::Measurement snt::puq::math::ceil(const puq::Measurement &msr)

Apply the ceil operation to this operand.

Parameters:

msr – Measurement whose value and uncertainty are transformed.

puq::Quantity snt::puq::math::ceil(const puq::Quantity &quant)

Apply the ceil operation to this operand.

Parameters:

quant – Quantity whose value and uncertainty are transformed.

puq::Result snt::puq::math::cos(const puq::Result &res)

Apply the cos operation to this operand.

Parameters:

res – Result whose estimate and uncertainty are transformed.

puq::Measurement snt::puq::math::cos(const puq::Measurement &msr)

Apply the cos operation to this operand.

Parameters:

msr – Measurement whose value and uncertainty are transformed.

puq::Quantity snt::puq::math::cos(const puq::Quantity &quant)

Apply the cos operation to this operand.

Parameters:

quant – Quantity whose value and uncertainty are transformed.

puq::Result snt::puq::math::exp(const puq::Result &res)

Apply the exp operation to this operand.

Parameters:

res – Result whose estimate and uncertainty are transformed.

puq::Measurement snt::puq::math::exp(const puq::Measurement &msr)

Apply the exp operation to this operand.

Parameters:

msr – Measurement whose value and uncertainty are transformed.

puq::Quantity snt::puq::math::exp(const puq::Quantity &quant)

Apply the exp operation to this operand.

Parameters:

quant – Quantity whose value and uncertainty are transformed.

puq::Result snt::puq::math::floor(const puq::Result &res)

Apply the floor operation to this operand.

Parameters:

res – Result whose estimate and uncertainty are transformed.

puq::Measurement snt::puq::math::floor(const puq::Measurement &msr)

Apply the floor operation to this operand.

Parameters:

msr – Measurement whose value and uncertainty are transformed.

puq::Quantity snt::puq::math::floor(const puq::Quantity &quant)

Apply the floor operation to this operand.

Parameters:

quant – Quantity whose value and uncertainty are transformed.

puq::Result snt::puq::math::log(const puq::Result &res)

Apply the log operation to this operand.

Parameters:

res – Result whose estimate and uncertainty are transformed.

puq::Measurement snt::puq::math::log(const puq::Measurement &msr)

Apply the log operation to this operand.

Parameters:

msr – Measurement whose value and uncertainty are transformed.

puq::Quantity snt::puq::math::log(const puq::Quantity &quant)

Apply the log operation to this operand.

Parameters:

quant – Quantity whose value and uncertainty are transformed.

puq::Result snt::puq::math::log10(const puq::Result &m)

Apply the log10 operation to this operand.

Parameters:

m – Result whose estimate and uncertainty are transformed.

puq::Measurement snt::puq::math::log10(const puq::Measurement &msr)

Apply the log10 operation to this operand.

Parameters:

msr – Measurement whose value and uncertainty are transformed.

puq::Quantity snt::puq::math::log10(const puq::Quantity &quant)

Apply the log10 operation to this operand.

Parameters:

quant – Quantity whose value and uncertainty are transformed.

puq::Result snt::puq::math::max(const puq::Result &res1, const puq::Result &res2)

Apply the max operation to this operand.

Parameters:
  • res1 – First result operand.

  • res2 – Second result operand.

puq::Measurement snt::puq::math::max(const puq::Measurement &msr1, const puq::Measurement &msr2)

Apply the max operation to this operand.

Parameters:
  • msr1 – First measurement operand.

  • msr2 – Second measurement operand.

puq::Quantity snt::puq::math::max(const puq::Quantity &quant1, const puq::Quantity &quant2)

Apply the max operation to this operand.

Parameters:
  • quant1 – First quantity operand.

  • quant2 – Second quantity operand.

puq::Result snt::puq::math::min(const puq::Result &res1, const puq::Result &res2)

Apply the min operation to this operand.

Parameters:
  • res1 – First result operand.

  • res2 – Second result operand.

puq::Measurement snt::puq::math::min(const puq::Measurement &msr1, const puq::Measurement &msr2)

Apply the min operation to this operand.

Parameters:
  • msr1 – First measurement operand.

  • msr2 – Second measurement operand.

puq::Quantity snt::puq::math::min(const puq::Quantity &quant1, const puq::Quantity &quant2)

Apply the min operation to this operand.

Parameters:
  • quant1 – First quantity operand.

  • quant2 – Second quantity operand.

puq::BaseUnits snt::puq::math::pow(puq::BaseUnits bu, const ExponentVariant &exp)

Apply the pow operation to this operand.

Parameters:
  • bu – Base-unit expression whose exponents are transformed.

  • exp – Exponent value.

puq::Result snt::puq::math::pow(const puq::Result &res, const double exp)

Apply the pow operation to this operand.

Parameters:
  • res – Result whose estimate and uncertainty are transformed.

  • exp – Exponent value.

puq::Result snt::puq::math::pow(const puq::Result &res1, const puq::Result &res2)

Apply the pow operation to this operand.

Parameters:
  • res1 – First result operand.

  • res2 – Second result operand.

puq::Measurement snt::puq::math::pow(const puq::Measurement &msr, const double exp)

Apply the pow operation to this operand.

Parameters:
puq::Measurement snt::puq::math::pow(const puq::Measurement &msr, const ExponentVariant &exp)

Apply the pow operation to this operand.

Parameters:
puq::Measurement snt::puq::math::pow(const puq::Measurement &msr1, const puq::Measurement &msr2)

Apply the pow operation to this operand.

Parameters:
  • msr1 – First measurement operand.

  • msr2 – Second measurement operand.

puq::Quantity snt::puq::math::pow(const puq::Quantity &quant1, const double exp)

Apply the pow operation to this operand.

Parameters:
  • quant1 – First quantity operand.

  • exp – Exponent value.

puq::Quantity snt::puq::math::pow(const puq::Quantity &quant1, const puq::Quantity &quant2)

Apply the pow operation to this operand.

Parameters:
  • quant1 – First quantity operand.

  • quant2 – Second quantity operand.

puq::Result snt::puq::math::round(const puq::Result &res)

Apply the round operation to this operand.

Parameters:

res – Result whose estimate and uncertainty are transformed.

puq::Measurement snt::puq::math::round(const puq::Measurement &msr)

Apply the round operation to this operand.

Parameters:

msr – Measurement whose value and uncertainty are transformed.

puq::Quantity snt::puq::math::round(const puq::Quantity &quant)

Apply the round operation to this operand.

Parameters:

quant – Quantity whose value and uncertainty are transformed.

puq::Result snt::puq::math::sin(const puq::Result &res)

Apply the sin operation to this operand.

Parameters:

res – Result whose estimate and uncertainty are transformed.

puq::Measurement snt::puq::math::sin(const puq::Measurement &msr)

Apply the sin operation to this operand.

Parameters:

msr – Measurement whose value and uncertainty are transformed.

puq::Quantity snt::puq::math::sin(const puq::Quantity &quant)

Apply the sin operation to this operand.

Parameters:

quant – Quantity whose value and uncertainty are transformed.

puq::BaseUnits snt::puq::math::sqrt(const puq::BaseUnits &bu)

Apply the sqrt operation to this operand.

Parameters:

bu – Base-unit expression whose exponents are transformed.

puq::Result snt::puq::math::sqrt(const puq::Result &res)

Apply the sqrt operation to this operand.

Parameters:

res – Result whose estimate and uncertainty are transformed.

puq::Measurement snt::puq::math::sqrt(const puq::Measurement &msr)

Apply the sqrt operation to this operand.

Parameters:

msr – Measurement whose value and uncertainty are transformed.

puq::Quantity snt::puq::math::sqrt(const puq::Quantity &quant)

Apply the sqrt operation to this operand.

Parameters:

quant – Quantity whose value and uncertainty are transformed.

puq::Result snt::puq::math::tan(const puq::Result &res)

Apply the tan operation to this operand.

Parameters:

res – Result whose estimate and uncertainty are transformed.

puq::Measurement snt::puq::math::tan(const puq::Measurement &msr)

Apply the tan operation to this operand.

Parameters:

msr – Measurement whose value and uncertainty are transformed.

puq::Quantity snt::puq::math::tan(const puq::Quantity &quant)

Apply the tan operation to this operand.

Parameters:

quant – Quantity whose value and uncertainty are transformed.