zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-users@zsh.org
Subject: Re: force floating point arithmetics
Date: Tue, 5 Mar 2013 20:02:19 +0000	[thread overview]
Message-ID: <20130305200219.54addb4a@pws-pc.ntlworld.com> (raw)
In-Reply-To: <20130305195147.690e801b@pws-pc.ntlworld.com>

On Tue, 5 Mar 2013 19:51:47 +0000
Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> Works quite well with zcalc, I should probably make it an option.

Index: Doc/Zsh/contrib.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/contrib.yo,v
retrieving revision 1.147
diff -p -u -r1.147 contrib.yo
--- Doc/Zsh/contrib.yo	26 Jan 2013 22:54:01 -0000	1.147
+++ Doc/Zsh/contrib.yo	5 Mar 2013 20:00:42 -0000
@@ -3158,6 +3158,10 @@ The output base can be initialised by pa
 for example `tt(zcalc -#16)' (the `tt(#)' may have to be quoted, depending
 on the globbing options set).
 
+If the option `tt(-f)' is set, all numbers are treated as floating
+point, hence for example the expression `tt(3/4)' evaluates to 0.75
+rather than 0.  Options must appear in separate words.
+
 The prompt is configurable via the parameter tt(ZCALCPROMPT), which
 undergoes standard prompt expansion.  The index of the current entry is
 stored locally in the first element of the array tt(psvar), which can be
Index: Functions/Misc/zcalc
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Misc/zcalc,v
retrieving revision 1.20
diff -p -u -r1.20 zcalc
--- Functions/Misc/zcalc	28 Jul 2010 14:01:12 -0000	1.20
+++ Functions/Misc/zcalc	5 Mar 2013 20:00:42 -0000
@@ -114,7 +114,7 @@ float PI E
 (( PI = 4 * atan(1), E = exp(1) ))
 
 # Process command line
-while [[ -n $1 && $1 = -(|[#-]*) ]]; do
+while [[ -n $1 && $1 = -(|[#-]*|f) ]]; do
   optlist=${1[2,-1]}
   shift
   [[ $optlist = (|-) ]] && break
@@ -139,6 +139,9 @@ while [[ -n $1 && $1 = -(|[#-]*) ]]; do
 	    fi
             defbase="[#${arg}]"
 	    ;;
+	(f) # Force floating point operation
+	    setopt forcefloat
+	    ;;
     esac
   done
 done

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


      reply	other threads:[~2013-03-05 20:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-04  7:29 Stephane Chazelas
2013-03-05 19:51 ` Peter Stephenson
2013-03-05 20:02   ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130305200219.54addb4a@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).