Skip to content

Instantly share code, notes, and snippets.

@songritk
Created September 12, 2017 08:52
Show Gist options
  • Save songritk/d2492edfd44724aab05c9368a6244072 to your computer and use it in GitHub Desktop.
Save songritk/d2492edfd44724aab05c9368a6244072 to your computer and use it in GitHub Desktop.
bash shell : trignometry
#!/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