From 26694406f22f0fe37d0b751066200bf0cfdec165 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 5 Mar 2013 20:06:59 +0000 Subject: users/17666: zcalc -f sets FORCE_FLOAT --- ChangeLog | 5 ++++- Doc/Zsh/contrib.yo | 4 ++++ Functions/Misc/zcalc | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19df9d5df..0cdc86d19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2013-03-05 Peter Stephenson + * users/17666: Doc/Zsh/contrib.yo, Functions/Misc/zcalc: -f + option to zcalc sets FORCE_FLOAT. + * users/17665: Doc/Zsh/options.yo, Src/math.c, Src/options.c, Src/zsh.h, Test/C01arith.ztst: add FORCE_FLOAT option. @@ -558,5 +561,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5811 $ +* $Revision: 1.5812 $ ***************************************************** diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 41a9d8158..14886d676 100644 --- a/Doc/Zsh/contrib.yo +++ b/Doc/Zsh/contrib.yo @@ -3158,6 +3158,10 @@ The output base can be initialised by passing the option `tt(-#)var(base)', 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 diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc index 2d0cf5d40..3d44f20db 100644 --- a/Functions/Misc/zcalc +++ b/Functions/Misc/zcalc @@ -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 -- cgit 1.4.1