Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: 3.1.6-pws-4: floating point support
- X-seq: zsh-workers 7946
- From: Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx (Zsh hackers list)
- Subject: Re: PATCH: 3.1.6-pws-4: floating point support
- Date: Mon, 20 Sep 1999 11:14:56 +0200
- In-reply-to: ""Bart Schaefer""'s message of "Sat, 18 Sep 1999 18:21:42 DFT." <990918182142.ZM6200@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
"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@xxxxxxxxxxxxxxxxx> Tel: +39 050 844536
WWW: http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy
Messages sorted by:
Reverse Date,
Date,
Thread,
Author