Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: force floating point arithmetics



On Tue, 5 Mar 2013 19:51:47 +0000
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> 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@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author