Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

forcing float arithmetic.




   #integer nn=4
   typeset -F nn=4
   typeset -F aa=

   (( aa = ((2 * nn) - 1) / (nn**2) ))
   echo $aa

If 'nn' is declared as an integer the above echos zero but if as a float the answer is correct.  But nn will never actually be other than an integer so I don't like to declare it as a float.  Am I not expecting successful arithmetic even with the integer?  I know you can force the issue with:

(( aa = ((2 * nn) - 1) / (nn**2.0) ))

... but I wonder why that's needed.  Why are answers dumbed down like that?  It's clearly a design decision but it seems to me unnatural.  If 'aa' was an integer too I understand the result would have to be rounded down to zero, but since aa is a float, shouldn't all arithmetic automatically produce floating point results?







Messages sorted by: Reverse Date, Date, Thread, Author