From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19257 invoked by alias); 4 Mar 2013 07:58:51 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17662 Received: (qmail 29501 invoked from network); 4 Mar 2013 07:58:49 -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.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW, T_DKIM_INVALID,T_TO_NO_BRKTS_FREEMAIL autolearn=no version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.212.182 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:date:from:to:cc:subject:message-id:mail-followup-to :mime-version:content-type:content-disposition:user-agent; bh=30jHytbzxziCQVO27EA9eVxZyuBErqx9tFZkkcgf17Q=; b=w19g8o0Gfoff2cWdtEdEYlTnFKTE7yahjDTqk9vfh29NK6kPbqLq45O6Ybe0GLaw8A 1hW9a5VDwmSuU4JI0w6hMjcf4aXb6mvvBAlfrsefZWDX3HO6CKOFYkXJgtt8qpaCS+PU rDFEOh9gSoJfDlLjoqXmCe+ZhRTKb4OnJAfFvRN13Vu4genNTynMBzoOV/l8QaytDfi0 lQDzvo2F+18wHBsdzvY6g74ApMGvKeS45OwwDS5AvxLUrqNxH7E4kyAuI1hBIQQRMp4u k0TgAwgBsGbdkxb6FRuRimosMu+7U8/Q5n2SWqjFxfiln0ij2T8qbZH7R/TcWA37VRNd u5Yg== X-Received: by 10.194.9.166 with SMTP id a6mr29853880wjb.2.1362382144248; Sun, 03 Mar 2013 23:29:04 -0800 (PST) Date: Mon, 4 Mar 2013 07:29:02 +0000 From: Stephane Chazelas To: zsh-users@zsh.org Cc: embe8573@student.uu.se Subject: force floating point arithmetics Message-ID: <20130304072902.GA9639@chaz.gmail.com> Mail-Followup-To: zsh-users@zsh.org, embe8573@student.uu.se MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Hiya, this is a follow up on http://unix.stackexchange.com/a/66755/22565 I was trying to find a way for $((...)) to always do floating point arithmetics as in $((1/3)) not returning 0, and the best I could come up with was appending . to any sequence of decimal digits that is not otherwise part of a hex number (or number in another base) or of a variable name or 12e-20 type numbers like: setopt extendedglob calc() printf '%.6g\n' $((${*//(#bm)(([0-9.]##[eE][-+][0-9]##|[[:alnum:]_#]#[.#_[:alpha:]][[:alnum:]_#]#)|([0-9]##))/$MATCH${match[3]:+.}})) alias 'calc=noglob calc' calc 1/3 ... Like the OP there, I'm surprised there's no easier way to do it, but maybe I've not looked hard enough. So, is there a way to force floating point arithmetics there even when entering integer constants? Thanks, Stephane