#include "tensorstore/util/unit.h"
struct tensorstore::Unit;

Represents a physical unit, such as “nm” or “3nm” or “3 m/s”.

A unit is defined by a numeric multiplier, represented as a double, and a base_unit, represented as a string. An empty string as the base_unit indicates a dimensionless quantity.

TensorStore does not itself interpret the base unit, but it is recommended to follow the syntax used by the udunits library:

https://www.unidata.ucar.edu/software/udunits/udunits-2.0.4/udunits2lib.html#Syntax

For example: “nm” or “nanometers” or “m/s” as the base_unit.

TensorStore does support a syntax for specifying a combined multiplier and base unit as a single string. Refer to the Unit(std::string_view unit) constructor documentation below for details.

Constructors

Unit();

Constructs a unit with an empty string as the base unit and a multiplier of 1.

Unit(std::string_view unit);
Unit(const charunit);
Unit(const std::stringunit);

Parses a combined multiplier and base unit from unit.

Unit(double multiplierstd::string base_unit);

Constructs from a multiplier and base unit.

Data members

double multiplier = 1;

Multiplier relative to the base_unit.

std::string base_unit;

Base unit specification.

Friend functions

friend std::ostreamoperator<<(std::ostreamosconst Unitunit);

Prints a string representation to an std::ostream.

friend void AbslStringify(Sinksinkconst Unitself);

Abseil formatting support.

friend bool operator==(const Unitaconst Unitb);
friend bool operator!=(const Unitaconst Unitb);

Compares two units for equality.

friend Unit operator*(Unit udouble x);
friend Unit operator*(double xUnit u);
friend Unitoperator*=(Unitudouble x);

Multiplies the multiplier.

friend Unit operator/(Unit udouble x);
friend Unitoperator/=(Unitudouble x);

Divides the multiplier.

Methods

std::string to_string() const;

Converts to the string representation.