diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-04-11 07:34:56 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-04-11 07:34:56 +0200 |
commit | 8a134ec68075fc2fd415558bcf6a37cda3ff285f (patch) | |
tree | e6c4927ebcb071b6dcb6e9832ebe6d7f4b721461 /coreutils/factor.c | |
parent | 10673c44f11045a0c99b19f32930097e9b3ae148 (diff) | |
download | busybox-w32-8a134ec68075fc2fd415558bcf6a37cda3ff285f.tar.gz busybox-w32-8a134ec68075fc2fd415558bcf6a37cda3ff285f.tar.bz2 busybox-w32-8a134ec68075fc2fd415558bcf6a37cda3ff285f.zip |
libbb: move isqrt from factor, use it in diff too
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/factor.c')
-rw-r--r-- | coreutils/factor.c | 19 |
1 files changed, 1 insertions, 18 deletions
diff --git a/coreutils/factor.c b/coreutils/factor.c index f910fdb44..11cc04f92 100644 --- a/coreutils/factor.c +++ b/coreutils/factor.c | |||
@@ -44,24 +44,7 @@ typedef unsigned long half_t; | |||
44 | #error Cant find an integer type which is half as wide as ullong | 44 | #error Cant find an integer type which is half as wide as ullong |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | /* Returns such x that x+1 > sqrt(N) */ | 47 | static half_t isqrt_odd(wide_t N) |
48 | static inline half_t isqrt(wide_t N) | ||
49 | { | ||
50 | half_t x; | ||
51 | unsigned shift; | ||
52 | |||
53 | shift = WIDE_BITS - 2; | ||
54 | x = 0; | ||
55 | do { | ||
56 | x = (x << 1) + 1; | ||
57 | if ((wide_t)x * x > (N >> shift)) | ||
58 | x--; /* whoops, that +1 was too much */ | ||
59 | shift -= 2; | ||
60 | } while ((int)shift >= 0); | ||
61 | return x; | ||
62 | } | ||
63 | |||
64 | static NOINLINE half_t isqrt_odd(wide_t N) | ||
65 | { | 48 | { |
66 | half_t s = isqrt(N); | 49 | half_t s = isqrt(N); |
67 | /* Subtract 1 from even s, odd s won't change: */ | 50 | /* Subtract 1 from even s, odd s won't change: */ |