diff --git a/doc/NEWS.Rd b/doc/NEWS.Rd index b4a953a5f5..48fbeaa341 100644 --- a/doc/NEWS.Rd +++ b/doc/NEWS.Rd @@ -349,6 +349,10 @@ integer to double, analogously with \code{seq.default()}, \code{seq.int()} and \code{seq.POSIXt()}, resolving a \emph{modified} \PR{18782}. + + \item The parser now accepts hexadecimal constants with a decimal + point without an exponent (taken as \code{p0}) as documented in + \code{?NumericConstants} (\PR{18819}). } } } diff --git a/src/main/gram.c b/src/main/gram.c index 672d2f1e9e..03cd3ec438 100644 --- a/src/main/gram.c +++ b/src/main/gram.c @@ -70,7 +70,7 @@ /* * R : A Computer Language for Statistical Data Analysis - * Copyright (C) 1997--2023 The R Core Team + * Copyright (C) 1997--2024 The R Core Team * Copyright (C) 2009--2011 Romain Francois * Copyright (C) 1995--1997 Robert Gentleman and Ross Ihaka * @@ -4930,7 +4930,8 @@ static int NumericValue(int c) YYTEXT_PUSH(c, yyp); if (nd == 0) return ERROR; } - if (seendot && !seenexp) return ERROR; +// ?NumericComstants says exponent is optional (as does C99) +// if (seendot && !seenexp) return ERROR; if (c == 'L') /* for getParseData */ { // seenexp will be checked later diff --git a/src/main/gram.y b/src/main/gram.y index 85d96bd30e..884e470bba 100644 --- a/src/main/gram.y +++ b/src/main/gram.y @@ -2,7 +2,7 @@ %{ /* * R : A Computer Language for Statistical Data Analysis - * Copyright (C) 1997--2023 The R Core Team + * Copyright (C) 1997--2024 The R Core Team * Copyright (C) 2009--2011 Romain Francois * Copyright (C) 1995--1997 Robert Gentleman and Ross Ihaka * @@ -2621,7 +2621,8 @@ static int NumericValue(int c) YYTEXT_PUSH(c, yyp); if (nd == 0) return ERROR; } - if (seendot && !seenexp) return ERROR; +// ?NumericComstants says exponent is optional (as does C99) +// if (seendot && !seenexp) return ERROR; if (c == 'L') /* for getParseData */ { // seenexp will be checked later diff --git a/tests/reg-tests-1e.R b/tests/reg-tests-1e.R index 6c61948cf0..e16d55cd03 100644 --- a/tests/reg-tests-1e.R +++ b/tests/reg-tests-1e.R @@ -1552,7 +1552,12 @@ for(x in list(x3 = {n <- 3L; x <- diag(n); x[n,n] <- 0; x}, } ## kappa(..) returned 1 or {0 with a warning} in R <= 4.4.2 - +## hexadecimal contants with and without exponent. +0x1.234p0 +0x1.234p7 +0x1.234p-7 +0x1.234 +## last was a (deliberate) parse error in R < 4.5.0, but not as documented. ## keep at end rbind(last = proc.time() - .pt,