From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27186 invoked by alias); 3 Sep 2012 12:35:23 -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: 30649 Received: (qmail 29132 invoked from network); 3 Sep 2012 12:35:11 -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.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Mon, 3 Sep 2012 12:40:01 +0100 From: Peter Stephenson To: "Zsh Hackers' List" Subject: Re: PATCH: (provisional) underscores in constants in numeric evaluation Message-ID: <20120903124001.12607c31@pwslap01u.europe.root.pri> In-Reply-To: <20120830151124.47ed724f@pwslap01u.europe.root.pri> References: <20120830151124.47ed724f@pwslap01u.europe.root.pri> Organization: Cambridge Silicon Radio 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-Originating-IP: [10.101.10.18] X-Scanned-By: MailControl 8316.0 (www.mailcontrol.com) on 10.68.0.119 Here are some documentation and tests. Index: Doc/Zsh/arith.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/arith.yo,v retrieving revision 1.14 diff -p -u -r1.14 arith.yo --- Doc/Zsh/arith.yo 19 Jun 2008 12:54:37 -0000 1.14 +++ Doc/Zsh/arith.yo 3 Sep 2012 11:34:20 -0000 @@ -48,6 +48,12 @@ The var(base)tt(#) may also be omitted, base 10 is used. For backwards compatibility the form `tt([)var(base)tt(])var(n)' is also accepted. +An integer expression or a base given in the form +`var(base)tt(#)var(n)', may contain underscores (`tt(_)') after the +leading digit for visual guidance; these are ignored in computation. +Examples are tt(1_000_000) or tt(0xffff_ffff) which are equivalent to +tt(1000000) and tt(0xffffffff) respectively. + It is also possible to specify a base to be used for output in the form `tt([#)var(base)tt(])', for example `tt([#16])'. This is used when outputting arithmetical substitutions or when assigning to scalar @@ -87,7 +93,9 @@ output is valid syntax for input. If th Floating point constants are recognized by the presence of a decimal point or an exponent. The decimal point may be the first character of the constant, but the exponent character tt(e) or tt(E) may not, as it will be -taken for a parameter name. +taken for a parameter name. All numeric parts (before and after the +decimal point and in the exponent) may contain underscores after the +leading digit for visual guidance; these are ignored in computation. cindex(arithmetic operators) cindex(operators, arithmetic) Index: Test/C01arith.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/C01arith.ztst,v retrieving revision 1.18 diff -p -u -r1.18 C01arith.ztst --- Test/C01arith.ztst 20 Jan 2010 17:18:30 -0000 1.18 +++ Test/C01arith.ztst 3 Sep 2012 11:34:20 -0000 @@ -210,3 +210,26 @@ print $x 0:double increment for repeated expression >2 + + # Floating point. Default precision should take care of rounding errors. + print $(( 1_0.000_000e0_1 )) + # Integer. + print $(( 0x_ff_ff_ )) + # _ are parts of variable names that don't start with a digit + __myvar__=42 + print $(( __myvar__ + $__myvar__ )) + # _ is not part of variable name that does start with a digit + # (which are substituted before math eval) + set -- 6 + print $(( $1_000_000 )) + # Underscores in expressions with no whitespace + print $(( 3_000_+4_000_/2 )) + # Underscores may appear in the base descriptor, for what it's worth... + print $(( 1_6_#f_f_ )) +0:underscores in math constants +>100. +>65535 +>84 +>6000000 +>5000 +>255 -- Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog