From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 677 invoked from network); 20 Sep 1999 10:17:14 -0000 Received: from mail2.primenet.com.au (HELO primenet.com.au) (?UgrhBCn/XaI97mXmkwxq6fsFyCzCG5GW?@203.24.36.6) by ns1.primenet.com.au with SMTP; 20 Sep 1999 10:17:14 -0000 Received: (qmail 2203 invoked from network); 20 Sep 1999 09:50:31 -0000 Received: from sunsite.auc.dk (130.225.51.30) by mail2.primenet.com.au with SMTP; 20 Sep 1999 09:50:31 -0000 Received: (qmail 29116 invoked by alias); 20 Sep 1999 09:50:11 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7946 Received: (qmail 29102 invoked from network); 20 Sep 1999 09:50:03 -0000 Message-Id: <9909200914.AA31751@ibmth.df.unipi.it> To: zsh-workers@sunsite.auc.dk (Zsh hackers list) Subject: Re: PATCH: 3.1.6-pws-4: floating point support In-Reply-To: ""Bart Schaefer""'s message of "Sat, 18 Sep 1999 18:21:42 DFT." <990918182142.ZM6200@candle.brasslantern.com> Date: Mon, 20 Sep 1999 11:14:56 +0200 From: Peter Stephenson "Bart Schaefer" wrote: > What's the most appropriate idiom for forcing a floating point number to be > interpreted as an integer, e.g. to force integer division? > > The thing that bothers me most -- and I don't know what if anything ksh does > about this, so maybe it's moot -- is that > > ((x=y)) > > where y is float and x was not previously defined, creates x as float, which > may be unexpected (if the assignment is in code that's held over from pre- > float zsh). Well, if y is a float but holds an integer you can get away with (( x = $(( y )) )) because the %g format used for outputting with $(( y )) doesn't use the decimal point unless it's necessary. But there's no mechanism for a cast other than making sure your parameters are declared appropriately. > While doing some random fooling around with this, I noticed: > > zagzig<23> ((integer florp=9.2)) > zsh: bad math expression: unbalanced stack > zagzig<24> typeset -F > florp=9.2000000000 > > The variable got assigned in spite of the syntax error? Ouch. The math parser is rather a hack; there's never been any proper syntax checking, which is why you always get that meaningless (to the user) error message. What happens here is that `integer' gets put on the stack as a parameter, then so does florp. Then when = is found, its right hand side is evaluated and the operator called. At that point, that operation is finished, so the parser goes back and finds it's now got `parameter value' on the stack with no operator. I'll see if I can think of something. -- Peter Stephenson Tel: +39 050 844536 WWW: http://www.ifh.de/~pws/ Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy