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")
Bash supports only integer arithmetic. You have many alternatives, one of them is awk
:
awk 'BEGIN {print 10**0.25}'
The good old standby bc
works as well
$ echo "e(0.25*l(10))" | bc -l
1.77827941003892280121
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With