|
3 | 3 | These are tests designed to test decimal to float conversions (`dec2flt`) used
|
4 | 4 | by the standard library.
|
5 | 5 |
|
6 |
| -Breakdown: |
| 6 | +The generators work as follows: |
7 | 7 |
|
8 |
| -- Generators (implement the `Generator` trait) provide test cases |
9 |
| -- We `.parse()` to the relevant float types and decompose it into its |
10 |
| - significand and its exponent. |
11 |
| -- Separately, we parse to an exact value with `BigRational` |
12 |
| -- Check sig + exp against `BigRational` math to make sure it is accurate within |
13 |
| - rounding, or correctly rounded to +/- inf. |
14 |
| -- `rayon` is awesome so this all gets parallelized nicely |
| 8 | +- Each generator is a struct that lives somewhere in the `gen` module. Usually |
| 9 | + it is generic over a float type. |
| 10 | +- These generators must implement `Iterator`, which should return a context |
| 11 | + type that can be used to construct a test string (but usually not the string |
| 12 | + itself). |
| 13 | +- They must also implement the `Generator` trait, which provides a method to |
| 14 | + write test context to a string as a test case, as well as some extra metadata. |
| 15 | + |
| 16 | + The split between context generation and string construction is so that |
| 17 | + we can reuse string allocations. |
| 18 | +- Each generator gets registered once for each float type. All of these |
| 19 | + generators then get iterated, and each test case checked against the float |
| 20 | + type's parse implementation. |
15 | 21 |
|
16 |
| -Some tests generate strings, others generate bit patterns. For those that |
17 |
| -generate bit patterns, we need to use float -> dec conversions so that also |
18 |
| -gets tested. |
| 22 | +Some tests produce decimal strings, others generate bit patterns that need |
| 23 | +to convert to the float type before printing to a string. For these, float to |
| 24 | +decimal (`flt2dec`) conversions get tested, if unintentionally. |
19 | 25 |
|
20 |
| -todo |
| 26 | +For each test case, the following is done: |
| 27 | + |
| 28 | +- The test string is parsed to the float type using the standard library's |
| 29 | + implementation. |
| 30 | +- The test string is parsed separately to a `BigRational`, which acts as a |
| 31 | + representation with infinite precision. |
| 32 | +- The rational value then gets checked that it is within the float's |
| 33 | + representable values (absolute value greater than the smallest number to |
| 34 | + round to zero, but less less than the first value to round to infinity). If |
| 35 | + these limits are exceeded, check that the parsed float reflects that. |
| 36 | +- For real nonzero numbers, the parsed float is converted into a |
| 37 | + rational using `significand * 2^exponent`. It is then checked against the |
| 38 | + actual rational value, and verified to be within half a bit's precision |
| 39 | + of the parsed value. |
| 40 | + |
| 41 | +This is all highly parallelized with `rayon`; test generators can run in |
| 42 | +parallel, and their tests get chunked and run in parallel. |
0 commit comments