From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: two mysteries
Date: Sat, 7 Nov 2015 01:55:34 -0800 [thread overview]
Message-ID: <151107015534.ZM23371@torch.brasslantern.com> (raw)
In-Reply-To: <563D281F.1000304@eastlink.ca>
On Nov 6, 2:22pm, Ray Andrews wrote:
}
} But what ended up happening is that the type check reported it as (can't
} recall) no longer integer, and I did the check just before the fatal
} division, so something had changed it previous to that.
My only guess is that in some cases the assignment occurs before the
declaration:
torch% START_IDX=1+((idx-1)/page_hight)*page_hight
torch% print ${(t)START_IDX}
scalar
torch% integer START_IDX
zsh: division by zero
torch% print ${(t)START_IDX}
integer
torch%
The value currently in the scalar $START_IDX is evaluated when the type
changes to integer, which causes the division by zero.
Interestingly, bash allows integers to have non-integer values, so
this is not an error there:
$ foo='1/0'
$ typeset -i foo
$ echo $foo
1/0
$ typeset -p foo
declare -i foo="1/0"
$
This is because bash does all the arithmetic only at assignment time.
} Didn't I read that
} there's a difference between 'typeset -i' and 'integer'?
Read where ...? Doc:
integer [ {+|-}Hghlprtux ] [ {+|-}LRZi [ N ] ] [ NAME[=VALUE] ... ]
Equivalent to typeset -i, except that options irrelevant to
integers are not permitted.
next prev parent reply other threads:[~2015-11-07 9:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-04 18:12 Ray Andrews
2015-11-04 20:35 ` Bart Schaefer
2015-11-05 0:38 ` Ray Andrews
2015-11-06 18:44 ` Bart Schaefer
2015-11-06 22:22 ` Ray Andrews
2015-11-07 9:55 ` Bart Schaefer [this message]
2015-11-07 15:19 ` Ray Andrews
2015-11-07 17:19 ` Bart Schaefer
2015-11-07 18:37 ` Ray Andrews
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=151107015534.ZM23371@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).