bc: make 2^1000000 interruptible faster
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 5 Dec 2018 00:21:59 +0000 (01:21 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 5 Dec 2018 14:43:35 +0000 (15:43 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
miscutils/bc.c

index 866fa30273fccb745ebd8ee9d6506a427421fcf2..b392b05a3b94298b70d91a93ee3ffbfc98d83911 100644 (file)
@@ -2039,6 +2039,11 @@ static BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
                powrdx <<= 1;
                s = bc_num_mul(&copy, &copy, &copy, powrdx);
                if (s) goto err;
+               // It is too slow to handle ^C only after entire "2^1000000" completes
+               if (G_interrupt) {
+                       s = BC_STATUS_FAILURE;
+                       goto err;
+               }
        }
 
        bc_num_copy(c, &copy);
@@ -2054,6 +2059,11 @@ static BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
                        s = bc_num_mul(c, &copy, c, resrdx);
                        if (s) goto err;
                }
+               // It is too slow to handle ^C only after entire "2^1000000" completes
+               if (G_interrupt) {
+                       s = BC_STATUS_FAILURE;
+                       goto err;
+               }
        }
 
        if (neg) {