@@ -168,16 +168,31 @@ By default, dimensions are stored as a `DynamicQuantities.FixedRational{Int32,C}
168168object, which represents a rational number
169169with a fixed denominator ` C ` . This is much faster than ` Rational ` .
170170
171- However, for many applications, ` FixedRational{Int8,6} ` will suffice,
171+ ``` julia
172+ julia> typeof (Quantity (0.5 , mass= 1 ))
173+ Quantity{Float64, FixedRational{Int32, 25200 }
174+ ```
175+
176+ You can change the type of the value field by initializing with a value
177+ of the desired type.
178+
179+ ``` julia
180+ julia> typeof (Quantity (Float16 (0.5 ), mass= 1 , length= 1 ))
181+ Quantity{Float16, FixedRational{Int32, 25200 }}
182+ ```
183+
184+ For many applications, `FixedRational{Int8,6}` will suffice,
172185and can be faster as it means the entire `Dimensions`
173- struct will fit into 64 bits. Let's see an example:
186+ struct will fit into 64 bits.
187+ You can change the type of the dimensions field by passing
188+ the type you wish to use as the second argument to `Quantity`:
174189
175190``` julia
176- julia> using DynamicQuantities; using DynamicQuantities : FixedRational
191+ julia> using DynamicQuantities
177192
178- julia> R8 = FixedRational{Int8,6 };
193+ julia> R8 = DynamicQuantities . FixedRational{Int8,6 };
179194
180- julia> R32 = FixedRational{Int32,2 ^ 4 * 3 ^ 2 * 5 ^ 2 * 7 }; # Default
195+ julia> R32 = DynamicQuantities . FixedRational{Int32,2 ^ 4 * 3 ^ 2 * 5 ^ 2 * 7 }; # Default
181196
182197julia> q8 = [Quantity (randn (), R8, length= rand (- 2 : 2 )) for i in 1 : 1000 ];
183198
@@ -199,7 +214,7 @@ like so:
199214
200215``` julia
201216julia> randn (5 ) .* Dimensions (mass= 2 / 5 , length= 2 )
202- 5 - element Vector{Quantity{Float64}}:
217+ 5 - element Vector{Quantity{Float64, FixedRational{Int32, 25200 } }}:
203218 - 0.6450221578668845 𝐋 ² 𝐌 ²ᐟ⁵
204219 0.4024829670050946 𝐋 ² 𝐌 ²ᐟ⁵
205220 0.21478863605789672 𝐋 ² 𝐌 ²ᐟ⁵
@@ -211,7 +226,7 @@ Because it is type stable, you can have mixed units in a vector too:
211226
212227``` julia
213228julia> v = [Quantity (randn (), mass= rand (0 : 5 ), length= rand (0 : 5 )) for _= 1 : 5 ]
214- 5 - element Vector{Quantity{Float64}}:
229+ 5 - element Vector{Quantity{Float64, FixedRational{Int32, 25200 } }}:
215230 2.2054411324716865 𝐌 ³
216231 - 0.01603602425887379 𝐋 ⁴ 𝐌 ³
217232 1.4388184352393647
0 commit comments