1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-02 22:11:54 +02:00

users/17665: add FORCE_FLOAT option

This commit is contained in:
Peter Stephenson 2013-03-05 20:04:53 +00:00
parent ac22eab0d9
commit 3def943d04
6 changed files with 53 additions and 1 deletions

View file

@ -1,5 +1,14 @@
2013-03-05 Peter Stephenson <p.w.stephenson@ntlworld.com>
* 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 <opk@zsh.org>
* 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 $
*****************************************************

View file

@ -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)

View file

@ -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;
}

View file

@ -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},

View file

@ -1988,6 +1988,7 @@ enum {
EXTENDEDHISTORY,
EVALLINENO,
FLOWCONTROL,
FORCEFLOAT,
FUNCTIONARGZERO,
GLOBOPT,
GLOBALEXPORT,

View file

@ -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.