zsh-users
 help / color / mirror / code / Atom feed
* force floating point arithmetics
@ 2013-03-04  7:29 Stephane Chazelas
  2013-03-05 19:51 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Stephane Chazelas @ 2013-03-04  7:29 UTC (permalink / raw)
  To: zsh-users; +Cc: embe8573

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-03-05 20:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-04  7:29 force floating point arithmetics Stephane Chazelas
2013-03-05 19:51 ` Peter Stephenson
2013-03-05 20:02   ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).