Quantity

coulomb.quantity$package$.Quantity$
object Quantity

Defines Quantity constructors and extension methods

Attributes

Source:
quantity.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Concise view

Type members

Classlikes

class Applier[U]

A shim class for Quantity companion object constructors

A shim class for Quantity companion object constructors

Attributes

Companion:
object
Source:
quantity.scala
Graph
Supertypes
class Object
trait Matchable
class Any
object Applier

Attributes

Companion:
class
Source:
quantity.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Applier.type

Value members

Concrete methods

def apply[U](using a: Applier[U]): Applier[U]

Lift a raw value of type V into a unit quantity

Lift a raw value of type V into a unit quantity

Attributes

U

the desired unit type

Returns:

a Quantity with given value and unit type

val distance = Quantity[Meter](1.0)
Source:
quantity.scala

Extensions

Extensions

extension [VL, UL](ql: Quantity[VL, UL])
transparent inline def *[VR, UR](qr: Quantity[VR, UR])(using mul: Mul[VL, UL, VR, UR]): Quantity[VO, UO]

multiply this quantity by another

multiply this quantity by another

Attributes

UR

right hand unit type

VR

right hand value type

qr

right hand quantity

Returns:

the product of this quantity with qr

Note:

result may depend on what algebras, policies, and other typeclasses are in scope

Example:
val q1 = 2.withUnit[Meter]
val q2 = (3.0).withUnit[Meter]
q1 * q2 // => Quantity[Meter ^ 2](6.0)
Source:
quantity.scala
transparent inline def +[VR, UR](qr: Quantity[VR, UR])(using add: Add[VL, UL, VR, UR]): Quantity[VO, UO]

add this quantity to another

add this quantity to another

Attributes

UR

right hand unit type

VR

right hand value type

qr

right hand quantity

Returns:

the sum of this quantity with qr

Note:

unit types UL and UR must be convertable

result may depend on what algebras, policies, and other typeclasses are in scope

Example:
val q1 = 1.withUnit[Meter]
val q2 = (1.0).withUnit[Yard]
q1 + q2 // => Quantity[Meter](1.9144)
Source:
quantity.scala
transparent inline def -[VR, UR](qr: Quantity[VR, UR])(using sub: Sub[VL, UL, VR, UR]): Quantity[VO, UO]

subtract another quantity from this one

subtract another quantity from this one

Attributes

UR

right hand unit type

VR

right hand value type

qr

right hand quantity

Returns:

the result of subtracting qr from this

Note:

unit types UL and UR must be convertable

result may depend on what algebras, policies, and other typeclasses are in scope

Example:
val q1 = 1.withUnit[Meter]
val q2 = (1.0).withUnit[Yard]
q1 - q2 // => Quantity[Meter](0.0856)
Source:
quantity.scala
transparent inline def /[VR, UR](qr: Quantity[VR, UR])(using div: Div[VL, UL, VR, UR]): Quantity[VO, UO]

divide this quantity by another

divide this quantity by another

Attributes

UR

right hand unit type

VR

right hand value type

qr

right hand quantity

Returns:

the quotient of this quantity with qr

Note:

result may depend on what algebras, policies, and other typeclasses are in scope

Example:
val q1 = 3.withUnit[Meter]
val q2 = (2.0).withUnit[Second]
q1 / q2 // => Quantity[Meter / Second](1.5)
Source:
quantity.scala
inline def <[VR, UR](qr: Quantity[VR, UR])(using ord: Ord[VL, UL, VR, UR]): Boolean

test if this quantity is less than another

test if this quantity is less than another

Attributes

UR

unit type of the right hand quantity

VR

value type of the right hand quantity

qr

the right hand quantity

Returns:

true if left-hand value is less than the right (after any conversions), false otherwise

Note:

result may depend on what algebras, policies, and other typeclasses are in scope

Example:
val q1 = 1000.withUnit[Liter]
val q2 = (2.0).withUnit[Meter ^ 3]
q1 < q2 // => true
Source:
quantity.scala
inline def <=[VR, UR](qr: Quantity[VR, UR])(using ord: Ord[VL, UL, VR, UR]): Boolean

test if this quantity is less than or equal to another

test if this quantity is less than or equal to another

Attributes

UR

unit type of the right hand quantity

VR

value type of the right hand quantity

qr

the right hand quantity

Returns:

true if left-hand value is less than or equal to the right (after any conversions), false otherwise

Note:

result may depend on what algebras, policies, and other typeclasses are in scope

Example:
val q1 = 1000.withUnit[Liter]
val q2 = (2.0).withUnit[Meter ^ 3]
q1 <= q2 // => true
Source:
quantity.scala
inline def =!=[VR, UR](qr: Quantity[VR, UR])(using ord: Ord[VL, UL, VR, UR]): Boolean

test this quantity for inequality with another

test this quantity for inequality with another

Attributes

UR

unit type of the right hand quantity

VR

value type of the right hand quantity

qr

the right hand quantity

Returns:

true if right hand value does not equal left (after any conversions), false otherwise

Note:

result may depend on what algebras, policies, and other typeclasses are in scope

Example:
val q1 = 1000.withUnit[Liter]
val q2 = (2.0).withUnit[Meter ^ 3]
q1 =!= q2 // => true
Source:
quantity.scala
inline def ===[VR, UR](qr: Quantity[VR, UR])(using ord: Ord[VL, UL, VR, UR]): Boolean

test this quantity for equality with another

test this quantity for equality with another

Attributes

UR

unit type of the right hand quantity

VR

value type of the right hand quantity

qr

the right hand quantity

Returns:

true if right hand value equals the left (after any conversions), false otherwise

Note:

result may depend on what algebras, policies, and other typeclasses are in scope

Example:
val q1 = 1000.withUnit[Liter]
val q2 = (1.0).withUnit[Meter ^ 3]
q1 === q2 // => true
Source:
quantity.scala
inline def >[VR, UR](qr: Quantity[VR, UR])(using ord: Ord[VL, UL, VR, UR]): Boolean

test if this quantity is greater than another

test if this quantity is greater than another

Attributes

UR

unit type of the right hand quantity

VR

value type of the right hand quantity

qr

the right hand quantity

Returns:

true if left-hand value is greater than the right (after any conversions), false otherwise

Note:

result may depend on what algebras, policies, and other typeclasses are in scope

Example:
val q1 = 2000.withUnit[Liter]
val q2 = (1.0).withUnit[Meter ^ 3]
q1 > q2 // => true
Source:
quantity.scala
inline def >=[VR, UR](qr: Quantity[VR, UR])(using ord: Ord[VL, UL, VR, UR]): Boolean

test if this quantity is greater than or equal to another

test if this quantity is greater than or equal to another

Attributes

UR

unit type of the right hand quantity

VR

value type of the right hand quantity

qr

the right hand quantity

Returns:

true if left-hand value is greater than or equal to the right (after any conversions), false otherwise

Note:

result may depend on what algebras, policies, and other typeclasses are in scope

Example:
val q1 = 2000.withUnit[Liter]
val q2 = (1.0).withUnit[Meter ^ 3]
q1 >= q2 // => true
Source:
quantity.scala
transparent inline def pow[P](using pow: Pow[VL, UL, P]): Quantity[VO, UO]

raise this quantity to a rational or integer power

raise this quantity to a rational or integer power

Attributes

P

the power, or exponent

Returns:

this quantity raised to exponent P

Example:
val q = (2.0).withUnit[Meter]
q.pow[2]  // => Quantity[Meter ^ 2](4.0)
q.pow[1/2]  // => Quantity[Meter ^ (1/2)](1.4142135623730951)
q.pow[-1]  // => Quantity[1 / Meter](0.5)
Source:
quantity.scala
inline def show: String

returns a string representing this Quantity, using unit abbreviations

returns a string representing this Quantity, using unit abbreviations

Attributes

Example:
val q = (1.5).withUnit[Meter / Second]
q.show // => "1.5 m/s"
Source:
quantity.scala
inline def showFull: String

returns a string representing this Quantity, using full unit names

returns a string representing this Quantity, using full unit names

Attributes

Example:
val q = (1.5).withUnit[Meter / Second]
q.showFull // => "1.5 meter/second"
Source:
quantity.scala
inline def tToUnit[U](using conv: TruncatingUnitConversion[VL, UL, U]): Quantity[VL, U]

convert a quantity to a new unit type, using an integral value type

convert a quantity to a new unit type, using an integral value type

Attributes

U

the new unit type

Returns:

a new Quantity having unit type U

Note:

attempting to convert to an incompatible unit will result in a compile error

Example:
val q = 10.withUnit[Yard]
q.tToUnit[Meter] // => Quantity[Meter](9)
Source:
quantity.scala
inline def tToValue[V](using conv: TruncatingValueConversion[VL, V]): Quantity[V, UL]

convert a quantity to an integer value type from a fractional type

convert a quantity to an integer value type from a fractional type

Attributes

V

a new integral value type

Returns:

a new Quantity having value type V

Example:
val q = (1.0).withUnit[Meter]
q.tToUnit[Long] // => Quantity[Meter](1L)
Source:
quantity.scala
inline def toUnit[U](using conv: UnitConversion[VL, UL, U]): Quantity[VL, U]

convert a quantity to a new unit type

convert a quantity to a new unit type

Attributes

U

the new unit type

Returns:

a new Quantity having unit type U

Note:

attempting to convert to an incompatible unit will result in a compile error

Example:
val q = (1.0).withUnit[Meter ^ 3]
q.toUnit[Liter] // => Quantity[Liter](1000.0)
q.toUnit[Hectare] // => compile error
Source:
quantity.scala
inline def toValue[V](using conv: ValueConversion[VL, V]): Quantity[V, UL]

convert a quantity to a new value type

convert a quantity to a new value type

Attributes

V

the new value type to use

Returns:

a new Quantity having value type V

Example:
val q = (1.0).withUnit[Meter]
q.toValue[Float] // => Quantity[Meter](1.0f)
Source:
quantity.scala
transparent inline def tpow[P](using tp: TPow[VL, UL, P]): Quantity[VO, UO]

raise this quantity to a rational or integer power, with integer truncated result

raise this quantity to a rational or integer power, with integer truncated result

Attributes

P

the power, or exponent

Returns:

this quantity raised to exponent P, truncated to integer type

Example:
val q = 10.withUnit[Meter]
q.tpow[2]  // => Quantity[Meter ^ 2](100)
q.tpow[1/2]  // => Quantity[Meter ^ (1/2)](3)
q.tpow[-1]  // => Quantity[1 / Meter](0)
Source:
quantity.scala
transparent inline def tquot[VR, UR](qr: Quantity[VR, UR])(using tq: TQuot[VL, UL, VR, UR]): Quantity[VO, UO]

divide this quantity by another, using truncating (integer) division

divide this quantity by another, using truncating (integer) division

Attributes

UR

right hand unit type

VR

right hand value type

qr

right hand quantity

Returns:

the integral quotient of this quantity with qr

Note:

result may depend on what algebras, policies, and other typeclasses are in scope

Example:
val q1 = 5.withUnit[Meter]
val q2 = 2L.withUnit[Second]
q1.tquot(q2) // => Quantity[Meter / Second](2L)
Source:
quantity.scala
inline def unary_-(using neg: Neg[VL, UL]): Quantity[VL, UL]

negate the value of a Quantity

negate the value of a Quantity

Attributes

Returns:

a Quantity having the negative of the original value

Example:
val q = 1.withUnit[Meter]
-q // => Quantity[Meter](-1)
Source:
quantity.scala
inline def value: VL

extract the raw value of a unit quantity

extract the raw value of a unit quantity

Attributes

Returns:

the underlying value, stripped of its unit information

val q = (1.5).withUnit[Meter]
q.value // => 1.5
Source:
quantity.scala