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

Re: almost floating point...



Jose Unpingco wrote on Fri August 15, at 20:59 -0700:
> I like to use the arithmetic abilities of zsh often and have noticed
> that 
> 
> z=1;
> echo $(( $z + 1/3*6  ))
> 
> doesn't add 2 to 1 =3. I think the intermediate divide operation
> confuses things somehow since

echo $(( $z + 6*1/3 )) should do what you need.  It appears * and /
have the same precedence, and the / appears first, so 1/3 = 0 is
computed first ... ;-)

When we learnt how to use a scientific calculator in school, we were
taught "BIMDAS" (Brackets, Indices, Multiplication, Division,
Addition, Subtraction).  In Real Life integer calculation, I've never
seen a system where M & D weren't equal precedence, associating left
to right.  Ditto for A & S.

cheers
,dunc
-- 
Duncan Sargeant  -  metacitizen  -  http://www.ucc.gu.uwa.edu.au/~dunc/



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