From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11093 invoked by alias); 15 Jan 2015 14:59:22 -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: 34290 Received: (qmail 2473 invoked from network); 15 Jan 2015 14:59:10 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f4-b7f126d000001e9a-b7-54b7d5ba5961 Date: Thu, 15 Jan 2015 14:58:45 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Math expression evaluation error? Message-id: <20150115145845.0e1e7901@pwslap01u.europe.root.pri> In-reply-to: <20150114153842.7b48aa93@pwslap01u.europe.root.pri> References: <54B03024.1030309@gmail.com> <20150109201552.1304eafe@ntlworld.com> <54B04ADA.9050102@gmail.com> <20150109224034.294d4fd6@ntlworld.com> <20150114150258.GA25519@ypig.lip.ens-lyon.fr> <20150114153842.7b48aa93@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrGLMWRmVeSWpSXmKPExsVy+t/xq7q7rm4PMXj91tLiYPNDJgdGj1UH PzAFMEZx2aSk5mSWpRbp2yVwZex7dY6xoFO0on1CI3MD42uBLkYODgkBE4nb03m6GDmBTDGJ C/fWs3UxcnEICSxllHg86QYjhLOESeLFwkXMEM42RolJ2/vZQFpYBFQlZr7exwhiswkYSkzd NBvMFhEQlzi79jwLiC0soCex+X0XmM0rYC+x/s1MJhCbU8BB4sSdmVDrfjNKTNvUBlbEL6Av cfXvJyaIm+wlZl45wwjRLCjxY/I9sBpmAS2JzduaWCFseYnNa94yg9hCAuoSN+7uZp/AKDQL ScssJC2zkLQsYGRexSiaWppcUJyUnmuoV5yYW1yal66XnJ+7iREStl92MC4+ZnWIUYCDUYmH l8Fve4gQa2JZcWXuIUYJDmYlEd7OHKAQb0piZVVqUX58UWlOavEhRiYOTqkGRukZ/z7aBd7u nn2mN6E9xOnBy5/2nPtqFZ41RFw6m8NqpmCReSDn98XH5k3iL1/dm/X4Z2I733WnlwzLOzO+ bJFs4ag85puxa/La+2a9ng4TFq4OOJZ3gGPjRZ+TfkVb2f8r6QTda3jut0vw2d2kZbxtT47+ tZZz+RNwX+jPssk/5vtUnnooEa7EUpyRaKjFXFScCACb6da7OQIAAA== On Wed, 14 Jan 2015 15:38:42 +0000 Peter Stephenson wrote: > I wouldn't have thought so --- I would guess when forcing floating > point calculations people would expect this to happen everywhere, > despite what the documentation for the option says. This notes the change of behaviour. pws diff --git a/README b/README index 4d2b6c1..d2b8b69 100644 --- a/README +++ b/README @@ -38,10 +38,12 @@ details, see the documentation. Incompatibilites between 5.0.7 and 5.0.8 ---------------------------------------- -A couple of arithmetic operations have changed: the new behaviour -is intended to be more consistent, but is not compatible with the old. +Various arithmetic operations have changed, in particular with respect +to the choice of integer or floating point operations. The new +behaviour is intended to be more consistent, but is not compatible with +the old. -Previously, the modulus operation, `%', implicitly converted the +1) Previously, the modulus operation, `%', implicitly converted the operation to integer and output an integer result, even if one or both of the arguments were floating point. Now, the C math library fmod() operator is used to implement the operation where @@ -57,7 +59,8 @@ New behaviour: % print $(( 5.5 % 2 )) 1.5 -Previously, assignments to variables assigned the correct type to + +2) Previously, assignments to variables assigned the correct type to variables declared as floating point or integer, but this type was not propagated to the value of the expression, as a C programmer would naturally expect. Now, the type of the variable is propagated @@ -81,6 +84,44 @@ New behaviour: % print $var 2 + +3) Previously, the FORCE_FLOAT option only forced the use of floating +point in arithmetic expressions for integers constants, i.e. numbers +typed directly into the expression, but not for variables. Hence +an operation involving only integer variables (or string variables +containing integers) was not forced to be performed with floating point +arithmetic. Now, operations involving variables are also forced to +floating point. For example: + +Old behaviour: + +% unsetopt FORCE_FLOAT +% print $(( 1 / 2 )) +0 +% integer i=1 j=2 +% print $(( i / j )) +0 +% setopt FORCE_FLOAT +% print $(( 1 / 2 )) +0.5 +% print $(( i / j )) +0 + +New behaviour: + +% unsetopt FORCE_FLOAT +% print $(( 1 / 2 )) +0 +% integer i=1 j=2 +% print $(( i / j )) +0 +% setopt FORCE_FLOAT +% print $(( 1 / 2 )) +0.5 +% print $(( i / j )) +0.5 + + Incompatibilities between 5.0.2 and 5.0.5 -----------------------------------------