Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
force floating point arithmetics
- X-seq: zsh-users 17662
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: force floating point arithmetics
- Date: Mon, 4 Mar 2013 07:29:02 +0000
- Cc: embe8573@xxxxxxxxxxxxx
- 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==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mail-followup-to: zsh-users@xxxxxxx, embe8573@xxxxxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author