Alias for multiply
Alias for multiply
scala> import spire.implicits._ scala> import shapeless.{ Witness => W, _ } scala> import libra.implicits._ scala> 2.m * 3.m res0: Quantity[Int, Term[Length, Metre, Fraction[W.`2`.T, W.`1`.T]] :: HNil] = Quantity(6)
Alias for add
Alias for add
scala> import spire.implicits._ scala> import shapeless.{ Witness => W, _ } scala> import libra.implicits._ scala> 3.m + 2.m res1: Quantity[Int, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(5)
Alias for subtract
Alias for subtract
scala> import spire.implicits._ scala> import shapeless.{ Witness => W, _ } scala> import libra.implicits._ scala> 3.m - 2.m res1: Quantity[Int, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(1)
Alias for divide
Alias for divide
scala> import spire.implicits._ scala> import shapeless.{ Witness => W, _ } scala> import libra.implicits._ scala> 4.0.m / 2.0.m res0: Quantity[Double, HNil] = Quantity(2.0)
Alias for quotient
Alias for quotient
scala> import spire.implicits._ scala> import shapeless.{ Witness => W, _ } scala> import libra.implicits._ scala> 5.m /~ 2.m res0: Quantity[Int, HNil] = Quantity(2)
Alias for power
Alias for power
scala> import spire.implicits._ scala> import shapeless.{ Witness => W, _ } scala> import shapeless.syntax.singleton._ scala> import libra.implicits._ scala> 2.0.m^(3.narrow) res0: Quantity[Double, Term[Length, Metre, Fraction[W.`3`.T, W.`1`.T]] :: HNil] = Quantity(8.0)
Adds another quantity using the spire AdditiveSemigroup.
Adds another quantity using the spire AdditiveSemigroup.
the quantity to add. This must have the equivalient dimensions.
scala> import spire.implicits._ scala> import shapeless.{ Witness => W, _ } scala> import libra.implicits._ scala> 3.m add 2.m res1: Quantity[Int, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(5)
Aligns the dimensions of a quantity.
Aligns the dimensions of a quantity.
Two quantities may have the same dimension, but have different parameter orders within their HLists. This reorders the dimensions such that the quantites have the same type. This is useful for algebra typeclasses which expect parameters to have the same type.
A dimension with the same parameters but a different parameter order
scala> import shapeless.{ Witness => W, _ } scala> import spire.implicits._ scala> import libra.implicits._ scala> type MetreKilogram = Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: Term[Mass, Kilogram, Fraction[W.`1`.T, W.`1`.T]] :: HNil scala> type KilogramMetre = Term[Mass, Kilogram, Fraction[W.`1`.T, W.`1`.T]] :: Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil scala> val q0: Quantity[Double, MetreKilogram] = Quantity(2.0) scala> val q1: Quantity[Double, KilogramMetre] = Quantity(3.0) // uses spire's Signed typeclass scala> q0 compare q1.as[MetreKilogram] res0: Int = -1
Divides by a quantity
Divides by a quantity
the quantity to divide by
scala> import spire.implicits._ scala> import shapeless.{ Witness => W, _ } scala> import libra.implicits._ scala> 4.0.m divide 2.0.m res0: Quantity[Double, HNil] = Quantity(2.0)
Raises the quantity to the power of -1
Raises the quantity to the power of -1
scala> import spire.implicits._ scala> import shapeless.{ Witness => W, _ } scala> import libra.implicits._ scala> val x = 2.0.m x: Quantity[Double, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(2.0) scala> x.invert res2: Quantity[Double, Term[Length, Metre, Fraction[W.`-1`.T, W.`1`.T]] :: HNil] = Quantity(0.5)
Multiplies by a quantity
Multiplies by a quantity
the quantity to multiply by
scala> import spire.implicits._ scala> import shapeless.{ Witness => W, _ } scala> import libra.implicits._ scala> 2.m multiply 3.m res0: Quantity[Int, Term[Length, Metre, Fraction[W.`2`.T, W.`1`.T]] :: HNil] = Quantity(6)
Negates the quantity
Negates the quantity
scala> import spire.implicits._ scala> import shapeless.{ Witness => W, _ } scala> import libra.implicits._ scala> val x = 2.m x: Quantity[Int, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(2) scala> x.negate res2: Quantity[Int, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(-2)
Raises to a power
Raises to a power
the Integer power to raise by
scala> import spire.implicits._ scala> import shapeless.{ Witness => W, _ } scala> import libra.implicits._ scala> 2.0.m.power[W.`3`.T] res0: Quantity[Double, Term[Length, Metre, Fraction[W.`3`.T, W.`1`.T]] :: HNil] = Quantity(8.0)
Euclidean division by a quantity
Euclidean division by a quantity
the quantity to divide by
the quotient of Euclidean division
scala> import spire.implicits._ scala> import shapeless.{ Witness => W, _ } scala> import libra.implicits._ scala> 5.m quotient 2.m res0: Quantity[Int, HNil] = Quantity(2)
The standard index form String
The standard index form String
scala> import spire.implicits._ scala> import libra.implicits._ scala> 2.m.show res0: String = 2 m [L]
Subtracts another quantity using the spire AdditiveGroup
Subtracts another quantity using the spire AdditiveGroup
the quantity to subtract. This must have the equivalient dimensions.
scala> import spire.implicits._ scala> import shapeless.{ Witness => W, _ } scala> import libra.implicits._ scala> 3.m subtract 2.m res1: Quantity[Int, Term[Length, Metre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(1)
Converts a quantity from one unit of measure to another
Converts a quantity from one unit of measure to another
The unit of measure to convert to
scala> import spire.implicits._ scala> import shapeless.{ Witness => W, _ } scala> import libra.implicits._ scala> 2.0.m.to[Centimetre] res0: Quantity[Double, Term[Length, Centimetre, Fraction[W.`1`.T, W.`1`.T]] :: HNil] = Quantity(200.0)
the coefficient
Represents a dimensional quantity
the Numeric type of the quantity e.g. Int, Float, Double
the dimensions
the coefficient