summaryrefslogtreecommitdiffhomepage
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-04-10 13:53:57 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-04-10 13:53:57 +0200
commitad5394d591896fc1d025efff2fa6c8c580fb67e9 (patch)
tree5885517e9057337fa886b0ccb863ccbe19dd188c /coreutils
parentdd3a3950531396296f062d4764f26c32a803458a (diff)
factor: add code to test isqrt() correctness
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/factor.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/coreutils/factor.c b/coreutils/factor.c
index 4a131813b..7400174a7 100644
--- a/coreutils/factor.c
+++ b/coreutils/factor.c
@@ -203,6 +203,23 @@ static NOINLINE void factorize(wide_t N)
int factor_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int factor_main(int argc UNUSED_PARAM, char **argv)
{
+#if 0 /* test isqrt() correctness */
+ wide_t n = argv[1] ? bb_strtoull(argv[1], NULL, 0) : time(NULL);
+ for (;;) {
+ half_t h;
+ if (--n == 0)
+ --n;
+ h = isqrt(n);
+ if (!(n & 0xff))
+ printf("isqrt(%llx)=%"HALF_FMT"x\n", n, h);
+ if ((wide_t)h * h > n)
+ return 1;
+ h++;
+ if (h != 0 && (wide_t)h * h <= n)
+ return 1;
+ }
+#endif
+
//// coreutils has undocumented option ---debug (three dashes)
//getopt32(argv, "");
//argv += optind;