Operate with powers of decimals in shell


I'm trying to make a shell script that takes numeric data that are usually decimal of type 0.00004 and I have to square them. Using "bc" the result I get 0.


echo "(0.0000003+0.0000005)^2"|bc

Looking at the help of bc, he says that I can raise numbers to powers as long as they are whole numbers

In what failure? If you know another method without using bc it does not matter to me ... Does anyone know any other way of doing operations within a script that is somewhat more flexible in that you have to make a slightly more complex account?

Greetings and thanks

asked by Arthur Hills 06.04.2018 в 22:57

1 answer


In principle bc does not support type float but if fixed decimals, pass the number of decimal places you want to use for operations with scale if it is omitted (by default) this value is 0, so round to integers

$ echo "scale=20; (0.0000003+0.0000005)^2"|bc
answered by 06.04.2018 / 23:02