From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: Re: PATCH: 3.1.6-pws-4: floating point support
Date: Mon, 20 Sep 1999 11:14:56 +0200 [thread overview]
Message-ID: <9909200914.AA31751@ibmth.df.unipi.it> (raw)
In-Reply-To: ""Bart Schaefer""'s message of "Sat, 18 Sep 1999 18:21:42 DFT." <990918182142.ZM6200@candle.brasslantern.com>
"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 <pws@ibmth.df.unipi.it> Tel: +39 050 844536
WWW: http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy
next prev parent reply other threads:[~1999-09-20 10:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-09-17 12:23 Peter Stephenson
1999-09-18 18:21 ` Bart Schaefer
1999-09-20 9:14 ` Peter Stephenson [this message]
1999-09-20 16:14 ` Peter Stephenson
1999-09-17 13:18 Sven Wischnowsky
1999-09-17 12:51 ` Peter Stephenson
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=9909200914.AA31751@ibmth.df.unipi.it \
--to=pws@ibmth.df.unipi.it \
--cc=zsh-workers@sunsite.auc.dk \
/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).