Arithmetic in floating point

is it not possible to simply di aritmetic without using bc or awk

i have tried folllowing operatrions but they support only integer types plz suggest me code for floating using values stored in the variables.the ans i get is integer and if i input floating values i get error numeric constant missing plz help

case $choice in

"1")
        add=`expr $a + $b`
        echo $add
        ;;

"2")
        sub=`expr $a - $b`
        echo $sub
        ;;

"3")

        mul=`expr $a \\* $b`
        echo $mul
        ;;
"4")
        div=`expr $a / $b`
        echo $div
        ;;

esac

You are correct - you need awk, perl, bc, etc. to do floating point arithmetic.
Not shell - shell does not support FP.

add=`echo "scale=1; $a / $b " | bc`

thanks buddy
it is not possible with expr to get floating poin answers

Correct (it's not possible).

Some newer shells, like ksh93 support floating point arithmetic, but for portability it's probably best to use bc.

A challenge could be to write a shell script that performs FP arithmetics.

Depending on the fractional resolution you require you can scale up all the numbers and use the fixed-point arithmetics. Other than this - it's not possible to have FP in shell as FP instructions are not a must-have for a Unix system machine and shells should be as portable as possible. For same reason i.e. Linux kernel does not have any floating point operation as well.

frans:
Below script:

echo "1 / 2" | bc -l

is a valid shell script performing FP arithmetics. But I know what you meant. :wink: