Quantity

com.phasmidsoftware.number.top.Quantity
See theQuantity companion object
case class Quantity[D <: Dimension](value: Valuable, unit: Unit[D]) extends Renderable

Represents a measurable quantity defined by a numerical value and a physical unit. The type parameter D specifies the dimension of the quantity.

This case class is useful for performing unit-aware numerical operations and rendering quantities in a human-readable format.

Value parameters

unit

the physical unit associated with the quantity, specified as a PhysicalUnit[D]

value

the numerical value of the quantity, which is represented as a Valuable

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait Renderable
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def *[D2 <: Dimension](other: Quantity[D2]): Quantity[MulDim[D, D2]]

Multiplies this quantity with another quantity, resulting in a new quantity whose dimension is the product of the dimensions of the two quantities.

Multiplies this quantity with another quantity, resulting in a new quantity whose dimension is the product of the dimensions of the two quantities.

Value parameters

other

the quantity to multiply with this quantity. The dimension of the other quantity must be of type D2, a subtype of Dimension.

Attributes

Returns

a new quantity representing the product of this quantity and the other quantity. The resulting quantity has a dimension defined as MulDim[D, D2].

def +(other: Quantity[D]): Option[Quantity[D]]

Adds this quantity to another quantity of the same dimension. If the units of both quantities are compatible, the resulting quantity is computed by converting the other quantity into the same unit as this quantity (if necessary) and summing their values.

Adds this quantity to another quantity of the same dimension. If the units of both quantities are compatible, the resulting quantity is computed by converting the other quantity into the same unit as this quantity (if necessary) and summing their values.

Value parameters

other

the quantity to be added, which must have the same dimension as this quantity.

Attributes

Returns

an Option containing the resulting quantity if the units are compatible, or None if the units are incompatible.

def /[D2 <: Dimension](other: Quantity[D2]): Quantity[DivDim[D, D2]]

Divides this quantity by another quantity, resulting in a new quantity whose dimension is the quotient of the dimensions of the two quantities.

Divides this quantity by another quantity, resulting in a new quantity whose dimension is the quotient of the dimensions of the two quantities.

Value parameters

other

the quantity to divide by. The dimension of the other quantity must be of type D2, a subtype of Dimension.

Attributes

Returns

a new quantity representing the quotient of this quantity and the other quantity. The resulting quantity has a dimension defined as DivDim[D, D2].

def in(targetUnit: Unit[D]): Option[Quantity[D]]

Converts this Quantity to an equivalent Quantity that has a different unit and returns the result as an Option of the converted quantity. The conversion is based on the scale factors of the source and target units relative to the Standard International (SI) base units. If the conversion is successful, a new Quantity instance is created with the converted value and target unit.

Converts this Quantity to an equivalent Quantity that has a different unit and returns the result as an Option of the converted quantity. The conversion is based on the scale factors of the source and target units relative to the Standard International (SI) base units. If the conversion is successful, a new Quantity instance is created with the converted value and target unit.

Value parameters

targetUnit

the physical unit to which this quantity should be converted. The dimension of the target unit must correspond to the dimension of this quantity.

Attributes

Returns

an Option containing the converted Quantity if the operation is valid, or None if the conversion cannot be performed due to the absence of a valid numerical value.

Inherited methods

def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product

Concrete fields

lazy val inverted: Quantity[DivDim[Dimensionless, D]]

Computes the multiplicative inverse of this quantity, resulting in a quantity that represents one divided by the value of this quantity.

Computes the multiplicative inverse of this quantity, resulting in a quantity that represents one divided by the value of this quantity.

Attributes

Returns

an Option containing the inverted quantity if the operation is valid, or None if the operation cannot be performed.

lazy val render: String

Renders the quantity as a string representation by combining the rendered value and the unit's symbol.

Renders the quantity as a string representation by combining the rendered value and the unit's symbol.

Attributes

Returns

a string consisting of the value's rendered representation followed by the unit's symbol, separated by a space

lazy val renderLaTeX: String

Convenience method for LaTeX rendering. Delegates to toLatex function in companion object.

Convenience method for LaTeX rendering. Delegates to toLatex function in companion object.

Attributes

lazy val squared: Quantity[MulDim[D, D]]

Computes the squared value of the quantity by multiplying it with itself.

Computes the squared value of the quantity by multiplying it with itself.

Attributes

Returns

an Option containing the squared quantity if the operation is valid, or None if the operation cannot be performed.