Quantity

com.phasmidsoftware.number.top.Quantity
See theQuantity companion class
object Quantity

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

Companion
class
Graph
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Quantity.type

Members list

Type members

Inherited and Abstract types

type MirroredElemLabels <: Tuple

The names of the product elements.

The names of the product elements.

Attributes

Inherited from:
Mirror
type MirroredLabel <: String

The name of the type.

The name of the type.

Attributes

Inherited from:
Mirror

Value members

Concrete methods

def apply[D <: Dimension](value: Number, unit: Unit[D]): Quantity[D]

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 Quantity instance representing the specified value and unit

def apply[D <: Dimension](value: Rational, unit: Unit[D]): Quantity[D]

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.

def apply[D <: Dimension](value: Int, unit: Unit[D]): Quantity[D]

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 Quantity instance with the specified value and unit

def apply[D <: Dimension](value: Double, unit: Unit[D]): Quantity[D]

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

def apply[D <: Dimension](value: String, unit: Unit[D]): Quantity[D]

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 Quantity instance representing the specified value and unit

def apply(value: Valuable): Quantity[Dimensionless]

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 Valuable to be associated with the Dimensionless unit

Attributes

Returns

a Quantity[Dimensionless] instance representing the specified value

def apply(value: Rational): Quantity[Dimensionless]

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 Rational to be associated with the Dimensionless unit

Attributes

Returns

a Quantity[Dimensionless] instance representing the specified value

def apply[D <: Dimension](value: Lazy, unit: Unit[D]): Quantity[D]

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 Quantity instance combining the specified value and unit

def apply(value: Int): Quantity[Dimensionless]

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 Dimensionless unit

Attributes

Returns

a Quantity[Dimensionless] instance representing the specified value

def apply(value: String): Quantity[Dimensionless]

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 Dimensionless unit

Attributes

Returns

a Quantity[Dimensionless] instance representing the numerical value as a dimensionless quantity

def lazify(valuable: Valuable): Expression

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 Valuable to be transformed into an Expression

Attributes

Returns

an Expression representing the given Valuable

def parse(value: Valuable, unit: String): Either[ParseError, Quantity[_]]

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 String representing the physical unit to be parsed and used with the value.

value

the numerical value of type Valuable to be combined with the unit.

Attributes

Returns

an Either containing a ParseError if the unit string failed parsing, or a Quantity[?] instance representing the parsed numerical value and unit.

def parse(quantity: String): Either[ParseError, Quantity[_]]

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 Try containing the parsed Quantity[?] if the input is successfully parsed, or a Failure with a UnitsParserException if an error occurs.

def toLatex[D <: Dimension](quantity: Quantity[D]): String

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

val unity: Quantity[Dimensionless]

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.

Attributes