mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-07-14 05:41:31 +02: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>
|
||||
|
||||
* Jun T: 33769: Test/comptest: workaround for KEYTIMEOUT to
|
||||
|
|
|
@ -39,7 +39,8 @@ zero status.
|
|||
cindex(arithmetic base)
|
||||
cindex(bases, in arithmetic)
|
||||
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)',
|
||||
where var(base) is a decimal number between two and thirty-six
|
||||
representing the arithmetic base and var(n)
|
||||
|
|
|
@ -449,12 +449,14 @@ lexconstant(void)
|
|||
nptr++;
|
||||
|
||||
if (*nptr == '0') {
|
||||
int lowchar;
|
||||
nptr++;
|
||||
if (*nptr == 'x' || *nptr == 'X') {
|
||||
lowchar = tolower(*nptr);
|
||||
if (lowchar == 'x' || lowchar == 'b') {
|
||||
/* Let zstrtol parse number with base */
|
||||
yyval.u.l = zstrtol_underscore(ptr, &ptr, 0, 1);
|
||||
/* Should we set lastbase here? */
|
||||
lastbase = 16;
|
||||
lastbase = (lowchar == 'b') ? 2 : 16;
|
||||
if (isset(FORCEFLOAT))
|
||||
{
|
||||
yyval.type = MN_FLOAT;
|
||||
|
|
|
@ -2082,6 +2082,8 @@ zstrtol_underscore(const char *s, char **t, int base, int underscore)
|
|||
base = 10;
|
||||
else if (*++s == 'x' || *s == 'X')
|
||||
base = 16, s++;
|
||||
else if (*s == 'b' || *s == 'B')
|
||||
base = 2, s++;
|
||||
else
|
||||
base = 8;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue