diff options
author | Andrew Morton <akpm@osdl.org> | 2003-12-29 05:42:51 -0800 |
---|---|---|
committer | Linus Torvalds <torvalds@home.osdl.org> | 2003-12-29 05:42:51 -0800 |
commit | e44db7e2a54d1d00c6984908693f1eaf9bc95641 (patch) | |
tree | aaf28a5ec7cbc4f72029f25fc4c6447ed7a313d4 /lib | |
parent | 9b1ace8b89ebd4220c09f97e097b5e4547d7f746 (diff) | |
download | history-e44db7e2a54d1d00c6984908693f1eaf9bc95641.tar.gz |
[PATCH] sqrt() fixes
It turns out that the int_sqrt() function in oom_kill.c gets it wrong.
But fb_sqrt() in fbmon.c gets its math right. Move that function into
lib/int_sqrt.c, and consolidate.
(oom_kill.c fix from Thomas Schlichter <schlicht@uni-mannheim.de>)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile | 2 | ||||
-rw-r--r-- | lib/int_sqrt.c | 32 |
2 files changed, 33 insertions, 1 deletions
diff --git a/lib/Makefile b/lib/Makefile index 3bc9013c4b9738..2fd41ecbb127d2 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -5,7 +5,7 @@ lib-y := errno.o ctype.o string.o vsprintf.o cmdline.o \ bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \ - kobject.o idr.o div64.o parser.o + kobject.o idr.o div64.o parser.o int_sqrt.o lib-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o diff --git a/lib/int_sqrt.c b/lib/int_sqrt.c new file mode 100644 index 00000000000000..a5d2cdc5684cfd --- /dev/null +++ b/lib/int_sqrt.c @@ -0,0 +1,32 @@ + +#include <linux/kernel.h> +#include <linux/module.h> + +/** + * int_sqrt - rough approximation to sqrt + * @x: integer of which to calculate the sqrt + * + * A very rough approximation to the sqrt() function. + */ +unsigned long int_sqrt(unsigned long x) +{ + unsigned long op, res, one; + + op = x; + res = 0; + + one = 1 << 30; + while (one > op) + one >>= 2; + + while (one != 0) { + if (op >= res + one) { + op = op - (res + one); + res = res + 2 * one; + } + res /= 2; + one /= 4; + } + return res; +} +EXPORT_SYMBOL(int_sqrt); |