From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12041 invoked by alias); 9 Jan 2015 22:40:42 -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: 34194 Received: (qmail 13816 invoked from network); 9 Jan 2015 22:40:40 -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,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-Originating-IP: [86.6.153.127] X-Spam: 0 X-Authority: v=2.1 cv=AoZg3YNP c=1 sm=1 tr=0 a=39NrsSuza2clQiZR/7fYWQ==:117 a=39NrsSuza2clQiZR/7fYWQ==:17 a=kj9zAlcOel0A:10 a=NLZqzBF-AAAA:8 a=pGLkceISAAAA:8 a=67ibQlIZqa9rzQvYC34A:9 a=CjuIK1q_8ugA:10 Date: Fri, 9 Jan 2015 22:40:34 +0000 From: Peter Stephenson To: jdh , zsh-workers@zsh.org Subject: Re: Math expression evaluation error? Message-ID: <20150109224034.294d4fd6@ntlworld.com> In-Reply-To: <54B04ADA.9050102@gmail.com> References: <54B03024.1030309@gmail.com> <20150109201552.1304eafe@ntlworld.com> <54B04ADA.9050102@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 09 Jan 2015 13:40:42 -0800 jdh wrote: > Thanks for the detailed explanation. I suggest that the an additional > line be added to the manual, which would say something like: > > " Caution: The evaluation of an expression is taken a term at a time > and if there are mixed terms , say integer only and float terms , the > integer only ones will not be promoted to real values and the result of > the whole expression would be an error to common standards. One can use > the -f option or the FORCE_FLOAT environment variable to change this > behavior." Thanks, that's just the sort of useful feedback on what people find confusing that we need. I've adapted it into the appropriate section of the manual with minor corrections. 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. + Scalar variables can hold integer or floating point values at different times; there is no memory of the numeric type in this case. pws