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

Re: two mysteries

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

torch% START_IDX=1+((idx-1)/page_hight)*page_hight
torch% print ${(t)START_IDX}
torch% integer START_IDX
zsh: division by zero
torch% print ${(t)START_IDX}

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
$ 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.

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