| 10 | |
| 11 | == Evaluating minimax polynomials == |
| 12 | |
| 13 | Let’s check how much an error on the last bit affects `float` variables, using relative error: |
| 14 | |
| 15 | {{{ |
| 16 | #!cpp |
| 17 | for (float f = 1e-25f; f < 50.0f; f *= 1.001f) |
| 18 | { |
| 19 | union { float f; uint32_t x; } u = { f }, v = u, w = u; |
| 20 | ++v.x; |
| 21 | --w.x; |
| 22 | printf("%e: %e %e\n", u.f, (v.f - u.f) / u.f, (u.f - w.f) / u.f); |
| 23 | } |
| 24 | }}} |
| 25 | |
| 26 | Plotting the results gives the answer: between `5.96e-8` and `1.19e-7`. |
| 27 | |
| 28 | How about `double`? |
| 29 | |
| 30 | {{{ |
| 31 | #!cpp |
| 32 | for (double d = 1e-25; d < 50.0; d *= 1.001) |
| 33 | { |
| 34 | union { double d; uint64_t x; } u = { d }, v = u, w = u; |
| 35 | ++v.x; |
| 36 | --w.x; |
| 37 | printf("%e: %e %e\n", u.d, (v.d - u.d) / u.d, (u.d - w.d) / u.d); |
| 38 | } |
| 39 | }}} |
| 40 | |
| 41 | Result: between `1.11e-16` and `2.22e-16`. |