-
#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 abase_unit
, represented as a string. An empty string as thebase_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 char* unit);
- Unit(const std::string& unit);
Parses a combined multiplier and base unit from
unit
.
- Unit(double multiplier, std::string base_unit);
Constructs from a multiplier and base unit.
Data members¶
- double multiplier = 1;
Multiplier relative to the
base_unit
.
Friend functions¶
- friend std::ostream& operator<<(std::ostream& os, const Unit& unit);
Prints a string representation to an
std::ostream
.
- friend void AbslStringify(Sink& sink, const Unit& self);
Abseil formatting support.
- friend bool operator==(const Unit& a, const Unit& b);
- friend bool operator!=(const Unit& a, const Unit& b);
Compares two units for equality.
- friend Unit operator*(Unit u, double x);
- friend Unit operator*(double x, Unit u);
- friend Unit& operator*=(Unit& u, double x);
Multiplies the
multiplier
.
- friend Unit operator/(Unit u, double x);
- friend Unit& operator/=(Unit& u, double x);
Divides the
multiplier
.
Methods¶