From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5230 invoked by alias); 14 Jan 2015 15:03:16 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34279 Received: (qmail 13743 invoked from network); 14 Jan 2015 15:03:03 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 Date: Wed, 14 Jan 2015 16:02:58 +0100 From: Vincent Lefevre To: zsh-workers@zsh.org Subject: Re: Math expression evaluation error? Message-ID: <20150114150258.GA25519@ypig.lip.ens-lyon.fr> Mail-Followup-To: zsh-workers@zsh.org References: <54B03024.1030309@gmail.com> <20150109201552.1304eafe@ntlworld.com> <54B04ADA.9050102@gmail.com> <20150109224034.294d4fd6@ntlworld.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20150109224034.294d4fd6@ntlworld.com> X-Mailer-Info: http://www.vinc17.net/mutt/ User-Agent: Mutt/1.5.23-6392-vl-r75100 (2015-01-06) On 2015-01-09 22:40:34 +0000, Peter Stephenson wrote: > diff --git a/Doc/Zsh/arith.yo b/Doc/Zsh/arith.yo > index a620b73..5c334ce 100644 > --- a/Doc/Zsh/arith.yo > +++ b/Doc/Zsh/arith.yo > @@ -233,6 +233,15 @@ necessary. In addition, if any operator which requires an integer > equivalents with assignment) is given a floating point argument, it will be > silently rounded down to the next integer. > > +Users should beware that, in common with many other programming > +languages but not software designed for calculation, the evaluation of > +an expression in zsh is taken a term at a time and promotion of integers > +to floating point does not occur in terms only containing integers. A > +typical result of this is that a division such as tt(6/8) is truncated, > +in this being rounded down to 0. The tt(FORCE_FLOAT) shell option can > +be used in scripts or functions where floating point evaluation is > +required throughout. This explanation is incorrect (or very ambiguous). FORCE_FLOAT doesn't force a floating-point evaluation; it just converts *constants* to floating-point. See the differences: ypig% setopt FORCE_FLOAT ypig% integer a=1 b=2 ypig% echo $((1/2)) 0.5 ypig% echo $((a/b)) 0 I'm wondering whether this is the expected behavior, though. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)