Fix q format spec (#1811)

This commit is contained in:
Rangi
2025-08-29 14:23:49 -04:00
committed by GitHub
parent 02b880e1b0
commit 85176ef10a
5 changed files with 16 additions and 7 deletions

View File

@@ -196,12 +196,19 @@ If specified, pads right-aligned numbers with zeros instead of spaces.
If specified, pads the value to this width, right-aligned with spaces by default.
.It Ql <frac> Ta May be
.Ql \&.
followed by one or more
followed by zero or more
.Ql 0
\[en]
.Ql 9 .
If specified, prints this many fractional digits of a fixed-point number.
Defaults to 5 digits, maximum 255 digits.
(A
.Ql \&.
followed by zero
.Ql 0
\[en]
.Ql 9
prints zero fractional digits.)
.It Ql <prec> Ta May be
.Ql q
followed by one or more

View File

@@ -77,9 +77,9 @@ void FormatSpec::useCharacter(int c) {
}
return;
// width
// frac
case '.':
if (state > FORMAT_WIDTH) {
if (state >= FORMAT_FRAC) {
break;
}
state = FORMAT_FRAC;
@@ -88,7 +88,7 @@ void FormatSpec::useCharacter(int c) {
// prec
case 'q':
if (state > FORMAT_PREC) {
if (state >= FORMAT_PREC) {
break;
}
state = FORMAT_PREC;

View File

@@ -2,7 +2,7 @@ println STRFMT("%+d %++d", 42, 42)
println STRFMT("%#x %##x", 42, 42)
println STRFMT("%-4d %--4d", 42, 42)
println STRFMT("%.f %..f", 42.0, 42.0)
println STRFMT("%qf %q.16f", 42.0, 42.0)
println STRFMT("%qf %q.16f %qq16f", 42.0, 42.0, 42.0)
DEF N = 42
println "{5d:N} {5d5:N}"

View File

@@ -10,6 +10,8 @@ error: Fixed-point constant precision 0 invalid, defaulting to 16
at invalid-format.asm(5)
error: STRFMT: Invalid format spec for argument 2
at invalid-format.asm(5)
error: STRFMT: Invalid format spec for argument 3
at invalid-format.asm(5)
error: Invalid format spec "5d5"
at invalid-format.asm(8)
error: Invalid format spec "xx"
@@ -28,4 +30,4 @@ error: Formatting type 'd' with fractional width
at invalid-format.asm(17)
error: Formatting type 'd' with fractional precision
at invalid-format.asm(18)
Assembly aborted with 15 errors!
Assembly aborted with 16 errors!

View File

@@ -2,7 +2,7 @@
$2a %x
42 %4d
42 %f
42.00000 %16f
42.00000 %16f %16f
42 42
2a 2a
hello