4 | %hide Data.List.replicate
6 | --------------------------------------------------------------------------------
7 | -- Fixed
8 | --------------------------------------------------------------------------------
10 | ||| The type of fixed-point fractional numbers.
11 | |||
17 | --------------------------------------------------------------------------------
18 | -- Show Utility
19 | --------------------------------------------------------------------------------
21 | ||| Render a fixed-point value to a string, with optional trailing zero chopping.
22 | |||
23 | ||| @chop whether to drop trailing zeros from the fractional part
24 | ||| @fa the fixed-point value, whose type index encodes resolution
25 | |||
26 | export
36 | chop
46 | where
52 | -1
56 | 0
58 | 1
73 | ""
85 | ""
92 | s
98 | ""
107 | --------------------------------------------------------------------------------
108 | -- Interfaces
109 | --------------------------------------------------------------------------------
141 | --------------------------------------------------------------------------------
142 | -- E0/Uni
143 | --------------------------------------------------------------------------------
145 | ||| +------------+---------------------+------+------------+
146 | ||| | Resolution | Scaling Factor | Type | show 12345 |
147 | ||| +============+=====================+======+============+
148 | ||| | E0 | 1\1 | Uni | 12345.0 |
149 | ||| +------------+---------------------+------+------------+
150 | |||
155 | --------------------------------------------------------------------------------
156 | -- E1/Deci
157 | --------------------------------------------------------------------------------
159 | ||| +------------+---------------------+------+------------+
160 | ||| | Resolution | Scaling Factor | Type | show 12345 |
161 | ||| +============+=====================+======+============+
162 | ||| | E1 | 1\10 | Deci | 1234.5 |
163 | ||| +------------+---------------------+------+------------+
164 | |||
169 | --------------------------------------------------------------------------------
170 | -- E2/Centi
171 | --------------------------------------------------------------------------------
173 | ||| +------------+---------------------+-------+------------+
174 | ||| | Resolution | Scaling Factor | Type | show 12345 |
175 | ||| +============+=====================+=======+============+
176 | ||| | E2 | 1\100 | Centi | 123.45 |
177 | ||| +------------+---------------------+-------+------------+
178 | |||
183 | --------------------------------------------------------------------------------
184 | -- E3/Milli
185 | --------------------------------------------------------------------------------
187 | ||| +------------+--------------------+-------+------------+
188 | ||| | Resolution | Scaling Factor | Type | show 12345 |
189 | ||| +============+====================+=======+============+
190 | ||| | E3 | 1\1000 | Milli | 12.345 |
191 | ||| +------------+--------------------+-------+------------+
192 | |||
197 | --------------------------------------------------------------------------------
198 | -- E4/TenthMilli
199 | --------------------------------------------------------------------------------
201 | ||| +------------+--------------------+------------+------------+
202 | ||| | Resolution | Scaling Factor | Type | show 12345 |
203 | ||| +============+====================+=======+=================+
204 | ||| | E4 | 1\10000 | TenthMilli | 1.2345 |
205 | ||| +------------+--------------------+------------+------------+
206 | |||
211 | --------------------------------------------------------------------------------
212 | -- E5/HundredthMilli
213 | --------------------------------------------------------------------------------
215 | ||| +------------+--------------------+------------------------+------------+
216 | ||| | Resolution | Scaling Factor | Type | show 12345 |
217 | ||| +============+====================+========================+============+
218 | ||| | E5 | 1\100000 | HundredthMilli | 0.12345 |
219 | ||| +------------+--------------------+------------------------+------------+
220 | |||
225 | --------------------------------------------------------------------------------
226 | -- E6/Micro
227 | --------------------------------------------------------------------------------
229 | ||| +------------+-------------------+-------+------------+
230 | ||| | Resolution | Scaling Factor | Type | show 12345 |
231 | ||| +============+===================+=======+============+
232 | ||| | E6 | 1\1000000 | Micro | 0.012345 |
233 | ||| +------------+-------------------+-------+------------+
234 | |||
239 | --------------------------------------------------------------------------------
240 | -- E7/DeciMicro
241 | --------------------------------------------------------------------------------
243 | ||| +------------+-------------------+-----------+------------+
244 | ||| | Resolution | Scaling Factor | Type | show 12345 |
245 | ||| +============+===================+===========+============+
246 | ||| | E7 | 1\10000000 | DeciMicro | 0.0012345 |
247 | ||| +------------+-------------------+-----------+------------+
248 | |||
253 | --------------------------------------------------------------------------------
254 | -- E8/CentiMicro
255 | --------------------------------------------------------------------------------
257 | ||| +------------+--------------------+------------+------------+
258 | ||| | Resolution | Scaling Factor | Type | show 12345 |
259 | ||| +============+====================+============+============+
260 | ||| | E8 | 1\100000000 | CentiMicro | 0.00012345 |
261 | ||| +------------+--------------------+------------+------------+
262 | |||
267 | --------------------------------------------------------------------------------
268 | -- E9/Nano
269 | --------------------------------------------------------------------------------
271 | ||| +------------+------------------+------+-------------+
272 | ||| | Resolution | Scaling Factor | Type | show 12345 |
273 | ||| +============+==================+======+=============+
274 | ||| | E9 | 1\1000000000 | Nano | 0.000012345 |
275 | ||| +------------+------------------+------+-------------+
276 | |||
281 | --------------------------------------------------------------------------------
282 | -- E10/DeciNano
283 | --------------------------------------------------------------------------------
285 | ||| +------------+-----------------+----------+--------------+
286 | ||| | Resolution | Scaling Factor | Type | show 12345 |
287 | ||| +============+=================+==========+==============+
288 | ||| | E10 | 1\10000000000 | DeciNano | 0.0000012345 |
289 | ||| +------------+-----------------+----------+--------------+
290 | |||
295 | --------------------------------------------------------------------------------
296 | -- E11/CentiNano
297 | --------------------------------------------------------------------------------
299 | ||| +------------+-----------------+-----------+---------------+
300 | ||| | Resolution | Scaling Factor | Type | show 12345 |
301 | ||| +============+=================+===========+===============+
302 | ||| | E11 | 1\100000000000 | CentiNano | 0.00000012345 |
303 | ||| +------------+-----------------+-----------+---------------+
304 | |||
309 | --------------------------------------------------------------------------------
310 | -- E12/Pico
311 | --------------------------------------------------------------------------------
313 | ||| +------------+-----------------+------+----------------+
314 | ||| | Resolution | Scaling Factor | Type | show 12345 |
315 | ||| +============+=================+======+================+
316 | ||| | E12 | 1\1000000000000 | Pico | 0.000000012345 |
317 | ||| +------------+-----------------+------+----------------+
318 | |||
323 | --------------------------------------------------------------------------------
324 | -- withResolution
325 | --------------------------------------------------------------------------------
327 | ||| Run a computation with the resolution available as an `Integer`.
328 | |||
329 | export