summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2021-05-20 18:26:15 +0200
committerMattias EngdegÄrd <mattiase@acm.org>2021-05-27 14:16:28 +0200
commitde45864cf787ce244b0d97e7cf523a6e03743f10 (patch)
tree903951ab9e9bf58b91e3f591f4a9d80603d112fa /src
parent40d2970f4360bd942ffc3f86db9ff1499a5a5393 (diff)
downloademacs-de45864cf787ce244b0d97e7cf523a6e03743f10.tar.gz
emacs-de45864cf787ce244b0d97e7cf523a6e03743f10.tar.bz2
emacs-de45864cf787ce244b0d97e7cf523a6e03743f10.zip
Fix lexing of numbers with trailing decimal point and exponent
Numbers with a trailing dot and an exponent were incorrectly read as integers (with the exponent ignored) instead of the floats they should be. For example, 1.e6 was read as the integer 1, not 1000000.0 as every sane person would agree was meant. (Bug#48678) Numbers with a trailing dot but no exponent are still read as integers. * src/lread.c (string_to_number): Fix float lexing. * test/src/lread-tests.el (lread-float): Add test. * doc/lispref/numbers.texi (Float Basics): Clarify syntax.
Diffstat (limited to 'src')
-rw-r--r--src/lread.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/lread.c b/src/lread.c
index bca53a9a37a..0b33fd0f254 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -3938,8 +3938,7 @@ string_to_number (char const *string, int base, ptrdiff_t *plen)
bool signedp = negative | positive;
cp += signedp;
- enum { INTOVERFLOW = 1, LEAD_INT = 2, DOT_CHAR = 4, TRAIL_INT = 8,
- E_EXP = 16 };
+ enum { INTOVERFLOW = 1, LEAD_INT = 2, TRAIL_INT = 4, E_EXP = 16 };
int state = 0;
int leading_digit = digit_to_number (*cp, base);
uintmax_t n = leading_digit;
@@ -3959,7 +3958,6 @@ string_to_number (char const *string, int base, ptrdiff_t *plen)
char const *after_digits = cp;
if (*cp == '.')
{
- state |= DOT_CHAR;
cp++;
}
@@ -4008,8 +4006,10 @@ string_to_number (char const *string, int base, ptrdiff_t *plen)
cp = ecp;
}
- float_syntax = ((state & (DOT_CHAR|TRAIL_INT)) == (DOT_CHAR|TRAIL_INT)
- || (state & ~INTOVERFLOW) == (LEAD_INT|E_EXP));
+ /* A float has digits after the dot or an exponent.
+ This excludes numbers like "1." which are lexed as integers. */
+ float_syntax = ((state & TRAIL_INT)
+ || ((state & LEAD_INT) && (state & E_EXP)));
}
if (plen)