mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-03 02:10:50 +02:00
commit bash-20130301 snapshot
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
#From: Syamala Rao Tadigadapa <stadigad@us.oracle.com>
|
||||
#Subject: Re: Division in ksh(getting the exact number) Please HELP
|
||||
#Date: Mon, 25 Oct 1999 15:05:08 -0700
|
||||
#Message-ID: <3814D414.7B896084@us.oracle.com>
|
||||
|
||||
#Here is how to calculate the (integer part of the) square root
|
||||
#of a number in a much cleaner way.
|
||||
|
||||
sqroot()
|
||||
{
|
||||
let arg=$1
|
||||
let root=arg
|
||||
while :
|
||||
do
|
||||
newroot=$(( (root+arg/root)/2 ))
|
||||
(( newroot == root )) && { echo $root; return; }
|
||||
let root=newroot
|
||||
done
|
||||
}
|
||||
|
||||
sqroot "$@"
|
||||
Reference in New Issue
Block a user