Provides factory methods for creating instances of the Quantity class.
Quantities represent measurable values associated with physical units and are parameterized by their dimension type D, which defines the specific physical property of the quantity (e.G., length, time, etc.).
The companion object offers multiple overloaded apply methods for constructing quantities using different types of numerical input.
Attributes
Members list
Type members
Inherited and Abstract types
The names of the product elements.
The names of the product elements.
Attributes
- Inherited from:
- Mirror
The name of the type.
The name of the type.
Attributes
- Inherited from:
- Mirror
Value members
Concrete methods
Constructs a new Quantity instance with the specified value and unit.
Constructs a new Quantity instance with the specified value and unit.
Value parameters
- unit
-
the physical unit associated with the quantity
- value
-
the numerical value of the quantity
Attributes
- Returns
-
a
Quantityinstance representing the specified value and unit
Creates a quantity with a specified value and physical unit, where the value is provided as a rational number.
Creates a quantity with a specified value and physical unit, where the value is provided as a rational number.
Value parameters
- unit
-
The physical unit associated with the quantity.
- value
-
The rational value representing the magnitude of the quantity.
Attributes
- Returns
-
A quantity with the specified value and unit.
Constructs a Quantity instance with an integer value and a corresponding physical unit.
Constructs a Quantity instance with an integer value and a corresponding physical unit.
Value parameters
- unit
-
the physical unit of the specified dimension associated with the quantity
- value
-
the integer value to be associated with the quantity
Attributes
- Returns
-
a
Quantityinstance with the specified value and unit
Constructs a Quantity instance from a Double value and a physical unit.
Constructs a Quantity instance from a Double value and a physical unit.
The method internally converts the given Double value to a Real representation and then utilizes the alternate apply method for Real values.
Value parameters
- unit
-
the physical unit associated with the quantity, of type
PhysicalUnit[D] - value
-
the numerical value of the quantity as a
Double
Attributes
- Returns
-
a
Quantity[D]instance representing the specified value and unit
Constructs a Quantity instance with the specified value and physical unit.
Constructs a Quantity instance with the specified value and physical unit.
This method interprets the provided value as a string and associates it with the given physical unit to create a measurable quantity.
Value parameters
- unit
-
the physical unit associated with the quantity
- value
-
the string representation of the quantity's numerical value
Attributes
- Returns
-
a
Quantityinstance representing the specified value and unit
Constructs a Quantity[Dimensionless] instance using the provided Valuable value.
Constructs a Quantity[Dimensionless] instance using the provided Valuable value.
This method associates the given Valuable numerical value with the Dimensionless unit, creating a quantity that represents a dimensionless measurement.
Value parameters
- value
-
the numerical value of type
Valuableto be associated with theDimensionlessunit
Attributes
- Returns
-
a
Quantity[Dimensionless]instance representing the specified value
Constructs a Quantity[Dimensionless] instance using the provided Rational value.
Constructs a Quantity[Dimensionless] instance using the provided Rational value.
This method associates the given Rational numerical value with the Dimensionless unit, creating a quantity that represents a dimensionless measurement.
Value parameters
- value
-
the numerical value of type
Rationalto be associated with theDimensionlessunit
Attributes
- Returns
-
a
Quantity[Dimensionless]instance representing the specified value
Creates a Quantity instance with the specified numerical value and physical unit.
Creates a Quantity instance with the specified numerical value and physical unit.
This method takes a lazy numerical value, which can be simplified, and a unit specifying the dimension of the quantity, and constructs a measurable quantity object of the given dimension.
Value parameters
- unit
-
the physical unit specifying the dimension of the quantity
- value
-
the lazy numerical value representing the magnitude of the quantity
Attributes
- Returns
-
a
Quantityinstance combining the specified value and unit
Constructs a Quantity[Dimensionless] instance with the given integer value.
Constructs a Quantity[Dimensionless] instance with the given integer value.
This method takes an integer value and associates it with the Dimensionless unit, creating a quantity that represents a dimensionless measurement.
Value parameters
- value
-
the integer value to be associated with the
Dimensionlessunit
Attributes
- Returns
-
a
Quantity[Dimensionless]instance representing the specified value
Constructs a Quantity[Dimensionless] instance from a string representation of a value.
Constructs a Quantity[Dimensionless] instance from a string representation of a value.
This method parses the input string to extract its numerical value and associates it with the Dimensionless unit to create a measurable quantity.
Value parameters
- value
-
the string representation of the numerical value to be parsed and associated with the
Dimensionlessunit
Attributes
- Returns
-
a
Quantity[Dimensionless]instance representing the numerical value as a dimensionless quantity
Converts a Valuable into an Expression while preserving lazy evaluation where applicable.
Converts a Valuable into an Expression while preserving lazy evaluation where applicable.
If the input is of type Eager, it is wrapped into an Expression. If the input is already an Expression, it is returned as is.
Value parameters
- valuable
-
the input value of type
Valuableto be transformed into anExpression
Attributes
- Returns
-
an
Expressionrepresenting the givenValuable
Parses a numerical value and a unit into a Quantity instance.
Parses a numerical value and a unit into a Quantity instance.
This method takes a Valuable numerical value and a String representing a unit. It first attempts to parse the unit string and, if successful, constructs a Quantity using the provided value and the parsed unit. If parsing the unit fails, it returns a Left containing the ParseError. NOTE this method is a flexible means of constructing a Quantity, but it suffers from the lack of type safety.
Value parameters
- unit
-
a
Stringrepresenting the physical unit to be parsed and used with the value. - value
-
the numerical value of type
Valuableto be combined with the unit.
Attributes
- Returns
-
an
Eithercontaining aParseErrorif the unit string failed parsing, or aQuantity[?]instance representing the parsed numerical value and unit.
Parses a string representation of a quantity into a Quantity instance.
Parses a string representation of a quantity into a Quantity instance.
This method interprets the input string, which should include a numerical value and an optional physical unit, and attempts to construct a measurable quantity. If parsing fails, it returns a Failure containing a UnitsParserException.
NOTE this method is the most flexible means of constructing a Quantity, but it suffers from the lack of type safety.
Value parameters
- quantity
-
the string representation of the quantity to be parsed. It is expected to include a numerical value followed optionally by a unit.
Attributes
- Returns
-
a
Trycontaining the parsedQuantity[?]if the input is successfully parsed, or aFailurewith aUnitsParserExceptionif an error occurs.
Render a quantity in LaTeX format. This is the definitive LaTeX rendering function.
Render a quantity in LaTeX format. This is the definitive LaTeX rendering function.
Value parameters
- quantity
-
the quantity to render
Attributes
- Returns
-
LaTeX string representation
Concrete fields
Represents the dimensionless unit quantity with a value of 1.
Represents the dimensionless unit quantity with a value of 1.
This predefined quantity is associated with the Dimensionless unit and is constructed with an integer value of 1. It can be used as a constant for operations requiring a base unit in dimensional analysis.