Formatting and mathematics

Formatting helpers and mathematical operations.

template<typename T>
std::string snt::core::number_to_string(const T &value, const StringFormatType &format = StringFormatType())

Format a scalar value according to format.

inline std::string snt::core::escape_quotes(const std::string &value, bool escape)

Escape double quotes in a string when requested.

template<typename T>
std::string snt::core::_array_to_string(const std::vector<T> &value, const std::vector<size_t> &shape, const DataType dtype, const StringFormatType &format, size_t &offset, size_t dim)
template<typename T>
std::string snt::core::array_to_string(const std::vector<T> &value, const std::vector<size_t> &shape, const DataType dtype, const StringFormatType &format = StringFormatType())

Format a multidimensional array of values according to its shape and type.

template<typename T>
std::string snt::core::number_to_string(const T &value, const T &uncertainty, const StringFormatType &format = StringFormatType())

Format a value together with its uncertainty.

template<typename T>
std::string snt::core::_array_to_string(const std::vector<T> &value, const std::vector<T> &uncertainty, const std::vector<size_t> &shape, const StringFormatType &format, size_t &offset, size_t dim)
template<typename T>
std::string snt::core::array_to_string(const std::vector<T> &value, const std::vector<T> &uncertainty, const std::vector<size_t> &shape, const StringFormatType &format = StringFormatType())

Format a multidimensional array of values and uncertainties.

std::string snt::core::to_string(const double value, int precision = static_cast<int>(std::cout.precision()))

Format a floating-point value with the requested precision.

Parameters:
  • value – Value to format.

  • precision – Number of significant digits.

Returns:

Formatted value.

struct StringFormatType
#include <string_format.h>

Formatting options shared by textual value and array renderers.

Public Members

char specifier

Format specifier: general, scientific (e), fixed (f), or decimal (d).

int valuePrecision

Number of significant digits used for values.

int uncertaintyPrecision

Number of significant digits used for uncertainties.

int thresholdScientific

Exponent at which general notation switches to scientific notation.

bool paddingZeros

Pad formatted output with zeroes instead of spaces.

int paddingSize

Minimum width of formatted output.

bool stringQuotes

Surround string values with quotes and escape embedded quotes.

double snt::core::math::abs(const double m)

Return the absolute value of a scalar.

Parameters:

m – Input value.

double snt::core::math::cbrt(const double m)

Return the real cube root of m.

Parameters:

m – Input value.

double snt::core::math::exp(const double e)

Return the natural exponential of e.

Parameters:

e – Exponent.

double snt::core::math::log(const double m)

Return the natural logarithm of m.

Parameters:

m – Positive input value.

double snt::core::math::log10(const double m)

Return the base-ten logarithm of m.

Parameters:

m – Positive input value.

double snt::core::math::max(const double m1, const double m2)

Return the larger of two scalar values.

Parameters:
  • m1 – First value.

  • m2 – Second value.

double snt::core::math::pow(const double m, const double e)

Return m raised to the power e.

Parameters:
  • m – Base value.

  • e – Exponent.

double snt::core::math::sqrt(const double m)

Return the non-negative square root of m.

Parameters:

m – Non-negative input value.