| 1565 | } |
| 1566 | |
| 1567 | AccuracyResult measure_smoothstep() { |
| 1568 | AccuracyResult r = {}; |
| 1569 | const int N = 10; // Spot testing: 10 key points adequate for [-0.5, 1.5] range (was 50) |
| 1570 | float sumErr = 0; |
| 1571 | for (int i = 0; i < N; ++i) { |
| 1572 | float x = -0.5f + 2.0f * i / (N - 1); |
| 1573 | float t = x < 0.0f ? 0.0f : (x > 1.0f ? 1.0f : x); |
| 1574 | float ref = t * t * (3.0f - 2.0f * t); |
| 1575 | float got = s16x16::smoothstep(s16x16(0.0f), s16x16(1.0f), s16x16(x)).to_float(); |
| 1576 | float err = fl::fabsf(got - ref); |
| 1577 | sumErr += err; |
| 1578 | if (err > r.maxErr) { r.maxErr = err; r.worstInput = x; } |
| 1579 | } |
| 1580 | r.avgErr = sumErr / N; |
| 1581 | r.nSamples = N; |
| 1582 | return r; |
| 1583 | } |
| 1584 | |
| 1585 | void print_row(const char *name, const AccuracyResult &r) { |
| 1586 | fl::printf("%s: maxErr=%.6f avgErr=%.6f worstInput=%.4f\n", |
no test coverage detected