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;
char const *after_digits = cp;
if (*cp == '.')
{
- state |= DOT_CHAR;
cp++;
}
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)
(should-error (read-event "foo: "))
(should-error (read-char-exclusive "foo: "))))
+(ert-deftest lread-float ()
+ (should (equal (read "13") 13))
+ (should (equal (read "+13") 13))
+ (should (equal (read "-13") -13))
+ (should (equal (read "13.") 13))
+ (should (equal (read "+13.") 13))
+ (should (equal (read "-13.") -13))
+ (should (equal (read "13.25") 13.25))
+ (should (equal (read "+13.25") 13.25))
+ (should (equal (read "-13.25") -13.25))
+ (should (equal (read ".25") 0.25))
+ (should (equal (read "+.25") 0.25))
+ (should (equal (read "-.25") -0.25))
+ (should (equal (read "13e4") 130000.0))
+ (should (equal (read "+13e4") 130000.0))
+ (should (equal (read "-13e4") -130000.0))
+ (should (equal (read "13e+4") 130000.0))
+ (should (equal (read "+13e+4") 130000.0))
+ (should (equal (read "-13e+4") -130000.0))
+ (should (equal (read "625e-4") 0.0625))
+ (should (equal (read "+625e-4") 0.0625))
+ (should (equal (read "-625e-4") -0.0625))
+ (should (equal (read "1.25e2") 125.0))
+ (should (equal (read "+1.25e2") 125.0))
+ (should (equal (read "-1.25e2") -125.0))
+ (should (equal (read "1.25e+2") 125.0))
+ (should (equal (read "+1.25e+2") 125.0))
+ (should (equal (read "-1.25e+2") -125.0))
+ (should (equal (read "1.25e-1") 0.125))
+ (should (equal (read "+1.25e-1") 0.125))
+ (should (equal (read "-1.25e-1") -0.125))
+ (should (equal (read "4.e3") 4000.0))
+ (should (equal (read "+4.e3") 4000.0))
+ (should (equal (read "-4.e3") -4000.0))
+ (should (equal (read "4.e+3") 4000.0))
+ (should (equal (read "+4.e+3") 4000.0))
+ (should (equal (read "-4.e+3") -4000.0))
+ (should (equal (read "5.e-1") 0.5))
+ (should (equal (read "+5.e-1") 0.5))
+ (should (equal (read "-5.e-1") -0.5))
+ (should (equal (read "0") 0))
+ (should (equal (read "+0") 0))
+ (should (equal (read "-0") 0))
+ (should (equal (read "0.") 0))
+ (should (equal (read "+0.") 0))
+ (should (equal (read "-0.") 0))
+ (should (equal (read "0.0") 0.0))
+ (should (equal (read "+0.0") 0.0))
+ (should (equal (read "-0.0") -0.0))
+ (should (equal (read "0e5") 0.0))
+ (should (equal (read "+0e5") 0.0))
+ (should (equal (read "-0e5") -0.0))
+ (should (equal (read "0e-5") 0.0))
+ (should (equal (read "+0e-5") 0.0))
+ (should (equal (read "-0e-5") -0.0))
+ (should (equal (read ".0e-5") 0.0))
+ (should (equal (read "+.0e-5") 0.0))
+ (should (equal (read "-.0e-5") -0.0))
+ (should (equal (read "0.0e-5") 0.0))
+ (should (equal (read "+0.0e-5") 0.0))
+ (should (equal (read "-0.0e-5") -0.0))
+ (should (equal (read "0.e-5") 0.0))
+ (should (equal (read "+0.e-5") 0.0))
+ (should (equal (read "-0.e-5") -0.0))
+ )
+
+
;;; lread-tests.el ends here