From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10484 invoked by alias); 9 Jan 2015 21:40:51 -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: 34191 Received: (qmail 8761 invoked from network); 9 Jan 2015 21:40:50 -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=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=4JnBeyZoAifz2JQY+eWCQ1C6uJ5xsBFUAg2LUlZxWJ0=; b=dwlu8xGUkffbWCxBRdUY1R4WpaunrkQfIyHpSZFrOSZs5y0aIvuADuy9ITUoKS98n2 HA0+pmYtaSl0gXpKhVIHdWRoFLcZhTQrLEDqOUPtGimqqNvH8Gw6CkQKI50/nU11OcG2 zJmrrywTDw45i7HCcsBxl+3z9bwauUT+Q5bHl2Q80NXjXGP8Tjn4a3Cu2cEWQZ+M9Gie IXafKyrKofSBrchvxw82oFo35RTVxo5k+izQcskaeM3hCS67Hk/sdlkXfOsyFM2r0j16 f7LFUctJk3VFF+KAu8vfpkSjZ0aBJ8zeYEKCNEFltF0KjmClc9q5f8oHxqwfb596PZJt YODA== X-Received: by 10.224.38.71 with SMTP id a7mr31271067qae.24.1420839644711; Fri, 09 Jan 2015 13:40:44 -0800 (PST) Message-ID: <54B04ADA.9050102@gmail.com> Date: Fri, 09 Jan 2015 13:40:42 -0800 From: jdh User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: zsh-workers@zsh.org Subject: Re: Math expression evaluation error? References: <54B03024.1030309@gmail.com> <20150109201552.1304eafe@ntlworld.com> In-Reply-To: <20150109201552.1304eafe@ntlworld.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit 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." I apologize if this is in the manual already. Regards. On 2015年01月09日 12:15, Peter Stephenson wrote: > On Fri, 09 Jan 2015 11:46:44 -0800 > jdh wrote: >> I believe I read that math expression evaluation will convert all >> calculations in an expression if "any" value in that expression is a >> real value. > This isn't the case and wherever this came from needs correcting. > Please instead read the documentation under ARITHMETIC EVALUATION in the > zshmisc manual for what actually happens and let us if know if you think > that is inadequate. The actually phrasing is "Promotion of integer to > floating point values is performed where necessary". It also refers > above that to C --- there's an underlying assumption here that the user > has some idea of the operation of C-like languages, which might of > course not be the case. "Where necessary" is in general where an > operator has a floating point number as one argument and an integer as > another; a C programmer would recognise the use of the word "promotion" > as implying this, a general user probably not. So the wording could > probably be improved. Brief and to the point suggestions on this from > anyone are welcome (long rambles on why anyone doesn't understand it > may be invigorating for the rambler but are less useful to us as > developers :-)). > > See also the following shell option: > > FORCE_FLOAT > Constants in arithmetic evaluation will be treated as floating > point even without the use of a decimal point. Integers in any > base will be converted. > > This is most useful in zcalc, which actually has an option for this. > > If the option `-f' is set, all numbers are treated as floating > point, hence for example the expression `3/4' evaluates to 0.75 > rather than 0. Options must appear in separate words. > > pws