Advertisement
MPogoda

sin in bash

May 30th, 2011
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.31 KB | None | 0 0
  1. function sin()
  2. {
  3.   if [ $# != 2 ]
  4.   then
  5.     echo "FAIL" >&2
  6.     return 2
  7.   fi
  8.  
  9.   result=$1
  10.   x=$1
  11.   n=1
  12.   fact=1
  13.   for k in `seq 2 $2`
  14.   do
  15.     x=$(( $x * $1 * $1 ))
  16.     n=$(( $n + 2 ))
  17.     fact=$(( (-1.0) * $fact * ($n - 1) * $n ))
  18.     result=$(( $result + $x / $fact ))
  19.   done
  20.   echo $result
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement