* strange arithmetic
@ 1997-11-28 19:09 Louis-David Mitterrand
1997-11-28 19:37 ` Andrew Main
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Louis-David Mitterrand @ 1997-11-28 19:09 UTC (permalink / raw)
To: zsh-users
(using 3.0.5)
% i=0;while [[ $[++i] < 900 ]];do;echo $i;done
% 1
% 2
[...]
% 90
90 ?? I asked for 900 and it stops at 90. On the other hand the
following:
% i=0;while ! [[ $[++i] = 900 ]];do;echo $i;done
% 1
% 2
[...]
% 899
Is this normal?
--
Louis-David Mitterrand
http://www.aparima.com
mito@aparima.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: strange arithmetic
1997-11-28 19:09 strange arithmetic Louis-David Mitterrand
@ 1997-11-28 19:37 ` Andrew Main
1997-11-28 20:16 ` Alain Caron
1997-11-29 11:44 ` Christopher Croughton
2 siblings, 0 replies; 7+ messages in thread
From: Andrew Main @ 1997-11-28 19:37 UTC (permalink / raw)
To: mito; +Cc: zsh-users
Louis-David Mitterrand wrote:
>% i=0;while [[ $[++i] < 900 ]];do;echo $i;done
"<" does a string comparison. For a numeric comparison, you want "-lt".
>% i=0;while ! [[ $[++i] = 900 ]];do;echo $i;done
"=" (or the preferred "==") also does string comparison. You should
really use "-eq" here.
I've just noticed that this is exactly the opposite convention from Perl.
I can even see why the difference was historically inevitable.
-zefram
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: strange arithmetic
1997-11-28 19:09 strange arithmetic Louis-David Mitterrand
1997-11-28 19:37 ` Andrew Main
@ 1997-11-28 20:16 ` Alain Caron
1997-11-28 20:30 ` Louis-David Mitterrand
1997-11-29 11:44 ` Christopher Croughton
2 siblings, 1 reply; 7+ messages in thread
From: Alain Caron @ 1997-11-28 20:16 UTC (permalink / raw)
To: mito; +Cc: zsh-users
Louis-David Mitterrand wrote:
> (using 3.0.5)
>
> % i=0;while [[ $[++i] < 900 ]];do;echo $i;done
> % 1
> % 2
> [...]
> % 90
>
> 90 ?? I asked for 900 and it stops at 90. On the other hand the
> following:
>
> % i=0;while ! [[ $[++i] = 900 ]];do;echo $i;done
> % 1
> % 2
> [...]
> % 899
>
> Is this normal?
>
> --
>
> Louis-David Mitterrand
> http://www.aparima.com
> mito@aparima.com
This is, I presume, because ">" and "=" are doing a lexicographic
comparison. For a numeric
comparison, use "-gt" and "-eq" operators.
Alain Caron
alainc@sangacorp.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: strange arithmetic
1997-11-28 20:16 ` Alain Caron
@ 1997-11-28 20:30 ` Louis-David Mitterrand
1997-11-29 2:04 ` Dan Nelson
0 siblings, 1 reply; 7+ messages in thread
From: Louis-David Mitterrand @ 1997-11-28 20:30 UTC (permalink / raw)
To: zsh-users
On Fri, Nov 28, 1997 at 03:16:37PM -0500, Alain Caron wrote:
> > % 90
> >
> > 90 ?? I asked for 900 and it stops at 90. On the other hand the
> > following:
> >
> > % i=0;while ! [[ $[++i] = 900 ]];do;echo $i;done
> > % 1
> > % 2
> > [...]
> > % 899
> >
> > Is this normal?
>
> This is, I presume, because ">" and "=" are doing a lexicographic
> comparison. For a numeric
> comparison, use "-gt" and "-eq" operators.
Thanks to you and zefram, I guess I've been exposed to Perl for a little
too long (the time I could put off learning shell scripting ;-).
And to think I thought I had discovered a bug in mighty zsh ..
--
Louis-David Mitterrand
http://www.aparima.com
mito@aparima.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: strange arithmetic
1997-11-28 20:30 ` Louis-David Mitterrand
@ 1997-11-29 2:04 ` Dan Nelson
1997-11-29 14:40 ` Louis-David Mitterrand
0 siblings, 1 reply; 7+ messages in thread
From: Dan Nelson @ 1997-11-29 2:04 UTC (permalink / raw)
To: mito; +Cc: zsh-users
In the last episode (Nov 28), Louis-David Mitterrand said:
> > > % i=0;while ! [[ $[++i] < 900 ]];do;echo $i;done
> > > % 1
> > > % 2
> > > [...]
> > > % 90
> > >
> > > Is this normal?
>
> Thanks to you and zefram, I guess I've been exposed to Perl for a little
> too long (the time I could put off learning shell scripting ;-).
>
> And to think I thought I had discovered a bug in mighty zsh ..
I'm not sure what Perl has to do with your confusion, unless Perl uses
[[ .. ]] to signify arithmetic evaluation? I'd check the Perl man
pages, but as they are split into 35 (!!!!!) sections, I won't. Thank
goodness for "man zshall".
I think [[ ]] is a builtin version of the test command, with more
testing capabilities.
You probably wanted to use the (( )) construct in zsh, to do arithmetic
evaluation of your test.
-Dan Nelson
dnelson@emsphone.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: strange arithmetic
1997-11-28 19:09 strange arithmetic Louis-David Mitterrand
1997-11-28 19:37 ` Andrew Main
1997-11-28 20:16 ` Alain Caron
@ 1997-11-29 11:44 ` Christopher Croughton
2 siblings, 0 replies; 7+ messages in thread
From: Christopher Croughton @ 1997-11-29 11:44 UTC (permalink / raw)
To: mito; +Cc: zsh-users
Louis-David Mitterrand wrote:
>
> (using 3.0.5)
>
> % i=0;while [[ $[++i] < 900 ]];do;echo $i;done
> % 1
> % 2
> [...]
> % 90
>
> 90 ?? I asked for 900 and it stops at 90. On the other hand the
> following:
It happens here with 3.1.2 as well. I can't see any logical reason...
Chris C
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: strange arithmetic
1997-11-29 2:04 ` Dan Nelson
@ 1997-11-29 14:40 ` Louis-David Mitterrand
0 siblings, 0 replies; 7+ messages in thread
From: Louis-David Mitterrand @ 1997-11-29 14:40 UTC (permalink / raw)
To: zsh-users
On Fri, Nov 28, 1997 at 08:04:44PM -0600, Dan Nelson wrote:
> In the last episode (Nov 28), Louis-David Mitterrand said:
> > > > % i=0;while ! [[ $[++i] < 900 ]];do;echo $i;done
> > > > % 1
> > > > % 2
> > > > [...]
> > > > % 90
> > > >
> > > > Is this normal?
> >
> > Thanks to you and zefram, I guess I've been exposed to Perl for a little
> > too long (the time I could put off learning shell scripting ;-).
> >
> > And to think I thought I had discovered a bug in mighty zsh ..
>
> I'm not sure what Perl has to do with your confusion, unless Perl uses
> [[ .. ]] to signify arithmetic evaluation? I'd check the Perl man
> pages, but as they are split into 35 (!!!!!) sections, I won't. Thank
> goodness for "man zshall".
>
> I think [[ ]] is a builtin version of the test command, with more
> testing capabilities.
>
> You probably wanted to use the (( )) construct in zsh, to do arithmetic
> evaluation of your test.
Aha! Right. I hadn't ventured deep engough in zsh's man pages. Sorry for
taking bandwidth with "should have RTFM'd" questions.
Right now I'm trying to understand bitwise manipulations and every day
that passes I thanks zsh for being such a wonderful prototyping tool. No
need to compile stuff, just type away and here comes the result... The
$[2#10010101] stuff comes real handy there to understand binary format.
Again, congratulations to zsh's developers. It's an awesome concentrate
of intelligence sitting behind that modest '%' prompt.
--
Louis-David Mitterrand
http://www.aparima.com
mito@aparima.com
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~1997-11-29 14:53 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-11-28 19:09 strange arithmetic Louis-David Mitterrand
1997-11-28 19:37 ` Andrew Main
1997-11-28 20:16 ` Alain Caron
1997-11-28 20:30 ` Louis-David Mitterrand
1997-11-29 2:04 ` Dan Nelson
1997-11-29 14:40 ` Louis-David Mitterrand
1997-11-29 11:44 ` Christopher Croughton
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).