[LTP] [PATCH] nextafter01: Check exact results and convert to new API
Petr Vorel
pvorel@suse.cz
Mon Oct 19 15:13:27 CEST 2026
Hi Jan,
> The test can hardly fail. Block 1 accepts nextafter(1.0, 1.1) whenever
> (answer + 1.0) / 2 rounds to 1.0 as a float, which is also true when
> nextafter() returns 1.0 unchanged. Block 2 never recomputes 'check'
> and compares the stale value from block 1, which is exactly 1.0, so its
> 'check != 1.0' condition is always false and any return value passes.
> Only the x == y case in block 3 is really verified. The file header also
> names the test "scalb".
> Compare the results with the exact next doubles instead: 1.0 + 2^-52
> above and 1.0 - 2^-53 below. Both are exactly representable, so a plain
> equality test is sufficient. Rewrite the test with the new API while at
> it and fix the description.
Thanks!
Reviewed-by: Petr Vorel <pvorel@suse.cz>
...
> -char *TCID = "nextafter01";
> +static struct tcase {
> + double x;
> + double y;
> + double exp;
> +} tcases[] = {
> + {1.0, 1.1, 1.0 + EPSILON},
> + {1.0, 0.9, 1.0 - EPSILON / 2},
> + {1.0, 1.0, 1.0},
> +};
...
> + if (ret == tc->exp) {
Hm, we still does not have TST_EXP_EQ_* variant for double.
Likely not worth of having it (not many tests comparing double).
Kind regards,
Petr
> + tst_res(TPASS, "nextafter(%g, %g) == %.17g", tc->x, tc->y, ret);
> + } else {
> + tst_res(TFAIL, "nextafter(%g, %g) == %.17g, expected %.17g",
> + tc->x, tc->y, ret, tc->exp);
More information about the ltp
mailing list