-
Notifications
You must be signed in to change notification settings - Fork 122
SQUIP 1: Generic Type for Underlying Quantity Value
By: Gary Keorkunian
This SQUIP describes a proposed change to the implementation of Quantity values. The proposed change aims to replace Double as the type for a Quantities underlying value with a Generic type. While Double is perhaps the type that provides the best performance, it does not offer the best precision in fractional operations which are quite common in dimensional analysis.
Currently, Squants uses a Double to store the underlying value of a Quantity.
val length: Length = Kilometers(100.0)
length.value.isInstanceOf[Double] should be(true)
The goal is to allow users to select the value type within their code. This will likely be achieved by adding a type parameter to each Quantity and it's Units. Users can choose from any type that supports "numeric" style operations.
val lengthDouble: Length[Double] = Kilometers(100.0)
length.value.isInstanceOf[Double] should be(true)
val lengthBigDecimal: Length[BigDecimal] = Kilometers(BigDecimal(100.0))
length.value.isInstanceOf[BigDecimal] should be(true)
Type inference should allow existing code, which uses Double, to continue working as expected.
The implementation required to solve what this SQUIP attempts to address is currently being researched. Initial research suggest that it will not be as simple as just replacing Double with a type parameter.