Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: forcing output type
- X-seq: zsh-users 4273
- From: Clint Adams <clint@xxxxxxx>
- To: Zefram <zefram@xxxxxxxx>
- Subject: Re: forcing output type
- Date: Sun, 23 Sep 2001 12:13:15 -0400
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <20010923164705.A15106@xxxxxxxx>; from zefram@xxxxxxxx on Sun, Sep 23, 2001 at 04:47:05PM +0100
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20010923114054.A16301@xxxxxxxx> <20010923164705.A15106@xxxxxxxx>
> 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 ))
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author