mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-12-09 18:51:46 +01:00
33793: add 0b binary interpretation to integer constants
This commit is contained in:
parent
c4110f7f4e
commit
a8927bf27b
4 changed files with 13 additions and 3 deletions
|
|
@ -1,3 +1,8 @@
|
||||||
|
2014-11-26 Peter Stephenson <p.stephenson@samsung.com>
|
||||||
|
|
||||||
|
* 33793: Src/math.c, Src/utils.c, Doc/Zsh/arith.yo: Arithmetic
|
||||||
|
constants beginning 0b specify binary.
|
||||||
|
|
||||||
2014-11-25 Oliver Kiddle <opk@zsh.org>
|
2014-11-25 Oliver Kiddle <opk@zsh.org>
|
||||||
|
|
||||||
* Jun T: 33769: Test/comptest: workaround for KEYTIMEOUT to
|
* Jun T: 33769: Test/comptest: workaround for KEYTIMEOUT to
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,8 @@ zero status.
|
||||||
cindex(arithmetic base)
|
cindex(arithmetic base)
|
||||||
cindex(bases, in arithmetic)
|
cindex(bases, in arithmetic)
|
||||||
Integers can be in bases other than 10.
|
Integers can be in bases other than 10.
|
||||||
A leading `tt(0x)' or `tt(0X)' denotes hexadecimal.
|
A leading `tt(0x)' or `tt(0X)' denotes hexadecimal and a leading
|
||||||
|
`tt(0b)' or `tt(0B) binary.
|
||||||
Integers may also be of the form `var(base)tt(#)var(n)',
|
Integers may also be of the form `var(base)tt(#)var(n)',
|
||||||
where var(base) is a decimal number between two and thirty-six
|
where var(base) is a decimal number between two and thirty-six
|
||||||
representing the arithmetic base and var(n)
|
representing the arithmetic base and var(n)
|
||||||
|
|
|
||||||
|
|
@ -449,12 +449,14 @@ lexconstant(void)
|
||||||
nptr++;
|
nptr++;
|
||||||
|
|
||||||
if (*nptr == '0') {
|
if (*nptr == '0') {
|
||||||
|
int lowchar;
|
||||||
nptr++;
|
nptr++;
|
||||||
if (*nptr == 'x' || *nptr == 'X') {
|
lowchar = tolower(*nptr);
|
||||||
|
if (lowchar == 'x' || lowchar == 'b') {
|
||||||
/* Let zstrtol parse number with base */
|
/* Let zstrtol parse number with base */
|
||||||
yyval.u.l = zstrtol_underscore(ptr, &ptr, 0, 1);
|
yyval.u.l = zstrtol_underscore(ptr, &ptr, 0, 1);
|
||||||
/* Should we set lastbase here? */
|
/* Should we set lastbase here? */
|
||||||
lastbase = 16;
|
lastbase = (lowchar == 'b') ? 2 : 16;
|
||||||
if (isset(FORCEFLOAT))
|
if (isset(FORCEFLOAT))
|
||||||
{
|
{
|
||||||
yyval.type = MN_FLOAT;
|
yyval.type = MN_FLOAT;
|
||||||
|
|
|
||||||
|
|
@ -2082,6 +2082,8 @@ zstrtol_underscore(const char *s, char **t, int base, int underscore)
|
||||||
base = 10;
|
base = 10;
|
||||||
else if (*++s == 'x' || *s == 'X')
|
else if (*++s == 'x' || *s == 'X')
|
||||||
base = 16, s++;
|
base = 16, s++;
|
||||||
|
else if (*s == 'b' || *s == 'B')
|
||||||
|
base = 2, s++;
|
||||||
else
|
else
|
||||||
base = 8;
|
base = 8;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue