Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Raise to non-integer exponent in bash?

How to raise a number to a non-integer exponent in bash?

For example, this:

 echo $((10**0.25))

works in zsh, but in Bash it gives the following error:

-bash: 10**0.25: syntax error: invalid arithmetic operator (error token is ".25")

like image 765
becko Avatar asked Sep 21 '25 12:09

becko


2 Answers

Bash supports only integer arithmetic. You have many alternatives, one of them is awk:

awk 'BEGIN {print 10**0.25}'
like image 162
Maroun Avatar answered Sep 23 '25 06:09

Maroun


The good old standby bc works as well

$ echo "e(0.25*l(10))" | bc -l
1.77827941003892280121
like image 39
David C. Rankin Avatar answered Sep 23 '25 08:09

David C. Rankin