From 3def943d046ad03540dd188ab52c0eacaa021149 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 5 Mar 2013 20:04:53 +0000 Subject: users/17665: add FORCE_FLOAT option --- ChangeLog | 11 ++++++++++- Doc/Zsh/options.yo | 11 +++++++++++ Src/math.c | 15 +++++++++++++++ Src/options.c | 1 + Src/zsh.h | 1 + Test/C01arith.ztst | 15 +++++++++++++++ 6 files changed, 53 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ea4124e63..19df9d5df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ +2013-03-05 Peter Stephenson + + * users/17665: Doc/Zsh/options.yo, Src/math.c, Src/options.c, + Src/zsh.h, Test/C01arith.ztst: add FORCE_FLOAT option. + 2013-02-27 Oliver Kiddle + * 31076: Completion/Linux/Command/_yast, + Completion/Unix/Type/_pids, Completion/Unix/Type/_pdf: + fix cases of more than one completion function for a command + * 31077: Completion/Unix/Command/_sort: update for new options in GNU sort @@ -549,5 +558,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5809 $ +* $Revision: 1.5811 $ ***************************************************** diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 6c8d423cb..ce24a2226 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -485,6 +485,17 @@ Treat the `tt(#)', `tt(~)' and `tt(^)' characters as part of patterns for filename generation, etc. (An initial unquoted `tt(~)' always produces named directory expansion.) ) +pindex(FORCE_FLOAT) +pindex(NO_FORCE_FLOAT) +pindex(FORCEFLOAT) +pindex(NOFORCEFLOAT) +cindex(floating point, forcing use of) +cindex(forcing use of floating point) +item(tt(FORCE_FLOAT))( +Constants in arithmetic evaluation will be treated as floating point +even without the use of a decimal point. Integers in any base +will be converted. +) pindex(GLOB) pindex(NO_GLOB) pindex(NOGLOB) diff --git a/Src/math.c b/Src/math.c index e90d6a59a..f8a4eefeb 100644 --- a/Src/math.c +++ b/Src/math.c @@ -456,6 +456,11 @@ lexconstant(void) yyval.u.l = zstrtol_underscore(ptr, &ptr, 0, 1); /* Should we set lastbase here? */ lastbase = 16; + if (isset(FORCEFLOAT)) + { + yyval.type = MN_FLOAT; + yyval.u.d = (double)yyval.u.l; + } return NUM; } else if (isset(OCTALZEROES)) @@ -475,6 +480,11 @@ lexconstant(void) { yyval.u.l = zstrtol_underscore(ptr, &ptr, 0, 1); lastbase = 8; + if (isset(FORCEFLOAT)) + { + yyval.type = MN_FLOAT; + yyval.u.d = (double)yyval.u.l; + } return NUM; } nptr = ptr2; @@ -537,6 +547,11 @@ lexconstant(void) lastbase = yyval.u.l; yyval.u.l = zstrtol_underscore(ptr, &ptr, lastbase, 1); } + if (isset(FORCEFLOAT)) + { + yyval.type = MN_FLOAT; + yyval.u.d = (double)yyval.u.l; + } } return NUM; } diff --git a/Src/options.c b/Src/options.c index b36bd9944..480fccd57 100644 --- a/Src/options.c +++ b/Src/options.c @@ -131,6 +131,7 @@ static struct optname optns[] = { {{NULL, "extendedhistory", OPT_CSH}, EXTENDEDHISTORY}, {{NULL, "evallineno", OPT_EMULATE|OPT_ZSH}, EVALLINENO}, {{NULL, "flowcontrol", OPT_ALL}, FLOWCONTROL}, +{{NULL, "forcefloat", 0}, FORCEFLOAT}, {{NULL, "functionargzero", OPT_EMULATE|OPT_NONBOURNE},FUNCTIONARGZERO}, {{NULL, "glob", OPT_EMULATE|OPT_ALL}, GLOBOPT}, {{NULL, "globalexport", OPT_EMULATE|OPT_ZSH}, GLOBALEXPORT}, diff --git a/Src/zsh.h b/Src/zsh.h index 207ef1836..f247563d4 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -1988,6 +1988,7 @@ enum { EXTENDEDHISTORY, EVALLINENO, FLOWCONTROL, + FORCEFLOAT, FUNCTIONARGZERO, GLOBOPT, GLOBALEXPORT, diff --git a/Test/C01arith.ztst b/Test/C01arith.ztst index 02d1519a4..71c8a1969 100644 --- a/Test/C01arith.ztst +++ b/Test/C01arith.ztst @@ -243,3 +243,18 @@ >6000000 >5000 >255 + + # Force floating point. + for expr in "3/4" "0x100/0x200" "0x30/0x10"; do + print $(( $expr )) + setopt force_float + print $(( $expr )) + unsetopt force_float + done +0:Forcing floating point constant evaluation, or not. +>0 +>0.75 +>0 +>0.5 +>3 +>3. -- cgit 1.4.1