* almost floating point...
@ 1997-08-16 3:59 Jose Unpingco
1997-08-16 6:58 ` Duncan Sargeant
0 siblings, 1 reply; 2+ messages in thread
From: Jose Unpingco @ 1997-08-16 3:59 UTC (permalink / raw)
To: zsh
hi,
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
z=1;
echo $(( $z + 6/3 ))
does add 2+1=3. I was wondering what the rules for this are? Also,
are there any compact alternatives if one needs to do batch floating
point computations through the shell without using PERL or AWK. For
example,
foreach file (numbers*.txt)
< $file | <compute floating point here somehow>
end
Thank you for your time and consideration.
----------------------------------------------------------------------
Jose Unpingco Mail Code ECE 0407; WK# (619) 534-5904
----------------------------------------------------------------------
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: almost floating point...
1997-08-16 3:59 almost floating point Jose Unpingco
@ 1997-08-16 6:58 ` Duncan Sargeant
0 siblings, 0 replies; 2+ messages in thread
From: Duncan Sargeant @ 1997-08-16 6:58 UTC (permalink / raw)
To: zsh
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/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1997-08-16 7:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-08-16 3:59 almost floating point Jose Unpingco
1997-08-16 6:58 ` Duncan Sargeant
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).