Created
September 12, 2017 08:52
-
-
Save songritk/d2492edfd44724aab05c9368a6244072 to your computer and use it in GitHub Desktop.
bash shell : trignometry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#trignometry | |
sin () | |
{ | |
echo "scale=5;s($1*0.017453293)" | bc -l | |
} | |
cos () | |
{ | |
echo "scale=5;c($1*0.017453293)" | bc -l | |
} | |
tan () | |
{ | |
echo "scale=5;s($1*0.017453293)/c($1*0.017453293)" | bc -l | |
} | |
csc () | |
{ | |
echo "scale=5;1/s($1*0.017453293)" | bc -l | |
} | |
sec () | |
{ | |
echo "scale=5;1/c($1*0.017453293)" | bc -l | |
} | |
ctn () | |
{ | |
echo "scale=5;c($1*0.017453293)/s($1*0.017453293)" | bc -l | |
} | |
asin () | |
{ | |
if (( $(echo "$1 == 1" | bc -l) ));then | |
echo "90" | |
elif (( $(echo "$1 < 1" | bc -l) ));then | |
echo "scale=3;a(sqrt((1/(1-($1^2)))-1))/0.017453293" | bc -l | |
elif (( $(echo "$1 > 1" | bc -l) ));then | |
echo "error" | |
fi | |
} | |
acos () | |
{ | |
if (( $(echo "$1 == 0" | bc -l) ));then | |
echo "90" | |
elif (( $(echo "$1 <= 1" | bc -l) ));then | |
echo "scale=3;a(sqrt((1/($1^2))-1))/0.017453293" | bc -l | |
elif (( $(echo "$1 > 1" | bc -l) ));then | |
echo "error" | |
fi | |
} | |
atan () | |
{ | |
echo "scale=3;a($1)/0.017453293" | bc -l | |
} | |
acot () | |
{ | |
echo "scale=5;a(1/$1)/0.017453293" | bc -l | |
} | |
asec () | |
{ | |
echo "scale=5;a(sqrt(($1^2)-1))/0.017453293" | bc -l | |
} | |
acsc () | |
{ | |
echo "scale=5;a(1/(sqrt($1^2)-1))/0.017453293" | bc -l | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment