1
votes

Trying to do

1*2^-2

tried code

echo "$((1 * (1/2**2)))" == 0
printf %.3f "$((1 * (1/2**2)))" == 0.000
also tried echo 1/2 | bc == 0

Problem seems that division operator is only not working maybe its a bug in cygwin Executing code in cygwin bash Help

2
bash arithmetic is integer only. 1/2 is equal to 0, not 0.5, in bash arithmetic. - M. Nejat Aydin
even bc and expr not working - Tathastu Pandya
i have limited tools on remote cygwin environment and tried using bc calculator but it was also producing 0 - Tathastu Pandya
bc is not related to bash and should work. Try echo "1/2^2" | bc -l - M. Nejat Aydin
ok -l works also echo "scale = 2; 1 * 2^-2" | bc works - Tathastu Pandya

2 Answers

1
votes

If awk is available:

$ awk 'BEGIN { print 1 * (1/2**2), 1* (1/2^2) }'
0.25 0.25

$ awk 'BEGIN { printf "%.3f / %.3f", 1 * (1/2**2), 1* (1/2^2) }'
0.250 / 0.250
0
votes
 echo "scale = 2; 1 * 2^-2" | bc

Also bc -l option works as suggested in comment