Q
Q
Quad_Tree2015-06-25 16:49:23
linux
Quad_Tree, 2015-06-25 16:49:23

How to calculate square root in Linux terminal?

I am writing a script and I need to calculate the root of a number. What command can I do this?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
B
Billy Milligan, 2015-06-25
@Quad_Tree

bc
examples , you need sqrt

E
Eddy_Em, 2015-06-25
@Eddy_Em

Here is a useful snippet from my ~/.bashrc:

function round(){ [ "$2" = "" ] && NUM=3 || NUM=$2; echo $1 | sed "s/\(*\.\{,$NUM\}\).*/\1/"; }
function sin(){ echo "scale=10; s($1*a(1)/45);" | bc -l; }
function cos(){ echo "scale=10; c($1*a(1)/45);" | bc -l; }
function tan(){ echo "scale=10; arg=$1*a(1)/45; s(arg)/c(arg);" | bc -l; }
function logn(){ echo "scale=10; l($1);" | bc -l; }
function log(){ echo "scale=10; l($1)/l(10);" | bc -l; }
function pow(){ echo "scale=10; ($1)^($2);" | bc -l; }
function sqrt(){ echo "scale=10; sqrt($1);" | bc -l; }
function exp(){ echo "scale=10; e($1);" | bc -l; }
function bin2hex(){ echo "obase=16;ibase=2;$1" | bc; }
function bin2dec(){ echo "obase=10;ibase=2;$1" | bc; }
function dec2hex(){ echo "obase=16;ibase=10;$1" | bc; }
function lower(){ echo $1 | tr [:upper:] [:lower:]; }
function upper(){ echo $1 | tr [:lower:] [:upper:]; }
function hex2binary(){ echo "obase=2;ibase=16; $(upper $1)" | bc; }
function hex2dec(){ echo "obase=10;ibase=16; $(upper $1)" | bc; }
alias pi="echo 'scale=10; a(1)*4;' | bc -l"
export PI=$(pi)

V
Vladimir, 2015-06-25
@azrail_dev

awk '{print sqrt($number)}'
Run, enter a number and voila)

A
Anton, 2015-06-25
@MoonMaster

probably so

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question