From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25724 invoked from network); 23 Sep 2001 16:13:40 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 23 Sep 2001 16:13:40 -0000 Received: (qmail 16939 invoked by alias); 23 Sep 2001 16:13:24 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 4273 Received: (qmail 16923 invoked from network); 23 Sep 2001 16:13:23 -0000 Date: Sun, 23 Sep 2001 12:13:15 -0400 From: Clint Adams To: Zefram Cc: zsh-users@sunsite.dk Subject: Re: forcing output type Message-ID: <20010923121315.A16711@dman.com> References: <20010923114054.A16301@dman.com> <20010923164705.A15106@fysh.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010923164705.A15106@fysh.org>; from zefram@fysh.org on Sun, Sep 23, 2001 at 04:47:05PM +0100 > The expression "2/3" is a truncating integer division; its value is > exactly 0. Just as in C, if you want to do a floating-point division > you have to provide floating-point operands. Here's a hack that lets one do "calc 2/3" and get a floating point answer. calc () { setopt localoptions extendedglob local expr="$*" if [[ "$expr" != *.* && "$expr" = *(#b)([0-9]##)(#B)' '#/' '#([0-9]##)* ]] then expr="${expr/${match[1]}/${match[1]}.0}" fi print $(( $expr )) }