@@ -168,16 +168,31 @@ By default, dimensions are stored as a `DynamicQuantities.FixedRational{Int32,C}
168
168
object, which represents a rational number
169
169
with a fixed denominator ` C ` . This is much faster than ` Rational ` .
170
170
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,
172
185
and 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`:
174
189
175
190
``` julia
176
- julia> using DynamicQuantities; using DynamicQuantities : FixedRational
191
+ julia> using DynamicQuantities
177
192
178
- julia> R8 = FixedRational{Int8,6 };
193
+ julia> R8 = DynamicQuantities . FixedRational{Int8,6 };
179
194
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
181
196
182
197
julia> q8 = [Quantity (randn (), R8, length= rand (- 2 : 2 )) for i in 1 : 1000 ];
183
198
@@ -199,7 +214,7 @@ like so:
199
214
200
215
``` julia
201
216
julia> randn (5 ) .* Dimensions (mass= 2 / 5 , length= 2 )
202
- 5 - element Vector{Quantity{Float64}}:
217
+ 5 - element Vector{Quantity{Float64, FixedRational{Int32, 25200 } }}:
203
218
- 0.6450221578668845 𝐋 ² 𝐌 ²ᐟ⁵
204
219
0.4024829670050946 𝐋 ² 𝐌 ²ᐟ⁵
205
220
0.21478863605789672 𝐋 ² 𝐌 ²ᐟ⁵
@@ -211,7 +226,7 @@ Because it is type stable, you can have mixed units in a vector too:
211
226
212
227
``` julia
213
228
julia> 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 } }}:
215
230
2.2054411324716865 𝐌 ³
216
231
- 0.01603602425887379 𝐋 ⁴ 𝐌 ³
217
232
1.4388184352393647
0 commit comments