propagating #i prefix across radix prefixes (issue #706)

This commit is contained in:
Alex Shinn 2020-09-22 17:37:22 +09:00
parent 993a6469fe
commit 4ef6c57d3e
2 changed files with 9 additions and 3 deletions

9
sexp.c
View file

@ -2799,7 +2799,7 @@ sexp sexp_ratio_normalize (sexp ctx, sexp rat, sexp in) {
sexp sexp_read_number (sexp ctx, sexp in, int base, int exactp) {
sexp_sint_t val = 0, tmp = -1;
int c, digit, negativep = 0;
int c, digit, negativep = 0, inexactp = 0;
#if SEXP_USE_PLACEHOLDER_DIGITS
double whole = 0.0, scale = 0.1;
#endif
@ -2813,7 +2813,7 @@ sexp sexp_read_number (sexp ctx, sexp in, int base, int exactp) {
switch ((c = sexp_tolower(sexp_read_char(ctx, in)))) {
case 'b': base = 2; break; case 'o': base = 8; break;
case 'd': base = 10; break; case 'x': base = 16; break;
case 'i': exactp = 0; break; case 'e': exactp = 1; break;
case 'i': inexactp = 1; break; case 'e': exactp = 1; break;
default: return sexp_read_error(ctx, "unexpected numeric # code", sexp_make_character(c), in);
}
c = sexp_read_char(ctx, in);
@ -2939,6 +2939,8 @@ sexp sexp_read_number (sexp ctx, sexp in, int base, int exactp) {
/ (double)sexp_unbox_fixnum(den));
#endif
}
if (inexactp)
res = sexp_exact_to_inexact(ctx, NULL, 2, res);
sexp_gc_release2(ctx);
return res;
#if SEXP_USE_COMPLEX
@ -2961,7 +2963,8 @@ sexp sexp_read_number (sexp ctx, sexp in, int base, int exactp) {
sexp_push_char(ctx, c, in);
}
return sexp_make_fixnum(negativep ? -val : val);
return inexactp ? sexp_make_flonum(ctx, negativep ? -val : val)
: sexp_make_fixnum(negativep ? -val : val);
}
#if SEXP_USE_UTF8_STRINGS

View file

@ -2398,6 +2398,9 @@
;; Combination of prefixes
(test-numeric-syntax "#e#x10" 16 "16")
(test-numeric-syntax "#i#x10" 16.0 "16.0" "16.")
(test-numeric-syntax "#x#i10" 16.0 "16.0" "16.")
(test-numeric-syntax "#i#x1/10" 0.0625 "0.0625")
(test-numeric-syntax "#x#i1/10" 0.0625 "0.0625")
;; (Attempted) decimal notation with base prefixes
(test-numeric-syntax "#d1." 1.0 "1.0" "1.")
(test-numeric-syntax "#d.1" 0.1 "0.1" ".1" "100.0e-3")