Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-10-23
09:32 • Ticket [2dff98e079] format %A garbles negative, padded and infinite values s... artifact: 51cb0e070f user: serhiy.storchaka
2026-10-18
21:07 • Closed ticket [2dff98e079]. artifact: 0252629989 user: jan.nijtmans
20:44 • Ticket [dbf9884c56] socket-14.19 and scan-15.1 fail on illumos status still ... artifact: 36bdf0d513 user: jan.nijtmans
20:09
Follow-up to [2dff98e079]: Fix testcases on MSVCRT check-in: 25cc9dd9b0 user: jan.nijtmans tags: core-9-0-branch
20:09
Follow-up to [2dff98e079]: Fix testcases on MSVCRT check-in: 185825858e user: jan.nijtmans tags: trunk, main
09:21 • Ticket [2dff98e079] format %A garbles negative, padded and infinite values s... artifact: f442407fa0 user: serhiy.storchaka
09:00 • Ticket [2dff98e079]: 3 changes artifact: de90a6a88b user: jan.nijtmans
08:59 • Ticket [2dff98e079]: 3 changes artifact: a6dc151432 user: jan.nijtmans
08:59 • Ticket [2dff98e079]: 3 changes artifact: 5cdae507bc user: jan.nijtmans
08:53 • Pending ticket [2dff98e079]. artifact: 4b524ff3ba user: jan.nijtmans
2026-10-17
07:25 • Closed ticket [2dff98e079]. artifact: 2f24eb1b1f user: serhiy.storchaka
07:22
Fix [2dff98e079]: format %A garbles negative, padded and infinite values check-in: 06f25062c2 user: serhiy.storchaka tags: core-9-0-branch
07:20
Fix [2dff98e079]: format %A garbles negative, padded and infinite values check-in: 9336b96c43 user: serhiy.storchaka tags: trunk, main
06:54 • Ticket [2dff98e079] format %A garbles negative, padded and infinite values s... artifact: c63cde0537 user: jan.nijtmans
2026-10-16
22:18 • Ticket [2dff98e079]: 3 changes artifact: fb24a449fa user: serhiy.storchaka
22:17
Fix [2dff98e079]: format %A garbled negative, padded and infinite values. Lowercase the "0X" prefix ... closed check-in: 5f07f3abba user: serhiy.storchaka tags: format-A-prefix
22:13 • New ticket [2dff98e079] format %A garbles negative, padded and infinite values</... artifact: df84203e20 user: serhiy.storchaka

format %A garbles negative, padded and infinite values

Closed / Fixed2dff98e0791720bdde656d47762553c1089684a4Created 47 days agoUpdated 41 days ago
Descriptionwiki2026-10-16 22:13:57
[format %A] overwrites the second character of the result with "x", assuming that it starts with "0X":
format %A -1.5    ;# -xX1.8p+0
format %+A 1.0    ;# +xX1p+0
format %10A 1.5   ;#  x0X1.8p+0
format %A Inf     ;# IxF

Only plain positive values come out right (0x1.8p+0). The code came with %a/%A in [5cfe15b5d6].

Referenced by7
  • 36bdf0d513Ticket [dbf9884c56] socket-14.19 and scan-15.1 fail on illumos status still Closed with 4 other changes ticket2026-10-18 20:44:01
  • 25cc9dd9b0Follow-up to [2dff98e079]: Fix testcases on MSVCRT check-in2026-10-18 20:09:53
  • 185825858eFollow-up to [2dff98e079]: Fix testcases on MSVCRT check-in2026-10-18 20:09:11
  • 4b524ff3baPending ticket [2dff98e079]: format %A garbles negative, padded and infinite values plus 4 other changes ticket2026-10-18 08:53:28
  • 06f25062c2Fix [2dff98e079]: format %A garbles negative, padded and infinite values check-in2026-10-17 07:22:40
  • 9336b96c43Fix [2dff98e079]: format %A garbles negative, padded and infinite values check-in2026-10-17 07:20:12
  • 5f07f3abbaFix [2dff98e079]: format %A garbled negative, padded and infinite values. Lowercase the "0X" prefix and the "P" exponent marker where they are, instead of assuming that the result starts with "0X". check-in2026-10-16 22:17:42
serhiy.storchakawiki2026-10-16 22:18:07

Proposed fix in branch format-A-prefix: lowercase the "0X" prefix and the "P" exponent marker where they are, which is after the padding and the sign, and leave INF alone. Test format-19.5.

jan.nijtmanswiki2026-10-17 06:54:38

+1

Please go ahead

serhiy.storchakawiki2026-10-17 07:25:45

Merged into main in [9336b96c43] and into 9.0 in [06f25062c2].

jan.nijtmanswiki2026-10-18 08:53:28

Just one thing left to fix. With msvcrt (not ucrt):

==== format-19.5 %A with sign, padding and Inf, bug [2dff98e079] FAILED
==== Contents of test case:

# explicit precision: without it MSVC prints all 13 hex digits list [format %.1A 1.5] [format %.1A -1.5] [format %+.0A 1.0] [format "% .0A" 1.0] [format %10.1A 1.5] [format %-10.0A| -2.0] [format %A Inf] [format %A -Inf]

---- Result was: 0x1.8p+0 -0x1.8p+0 +0x1p+0 { 0x1p+0} { 0x1.8p+0} {-0x1p+1 |} 0x1.#INF00p+0 -0x1.#INF00p+0 ---- Result should have been (exact matching): 0x1.8p+0 -0x1.8p+0 +0x1p+0 { 0x1p+0} { 0x1.8p+0} {-0x1p+1 |} INF -INF ==== format-19.5 FAILED

Matching with -glob would be easiest: If it contains 'INF' that should be OK

jan.nijtmanswiki2026-10-18 08:59:20

My proposal [6715b0e7eddf95f|here] (unless someone has a better idea)

jan.nijtmanswiki2026-10-18 08:59:32

My proposal [6715b0e7eddf95f|here] (unless someone has a better idea)

jan.nijtmanswiki2026-10-18 09:00:57

My proposal [here] (unless someone has a better idea)

serhiy.storchakawiki2026-10-18 09:21:47

Another option, done in [f5bb9702a9]: format infinities ourselves instead of passing them to the C library, as Python does. msvcrt gets them wrong for all float conversions, not only %A (1.#INF00e+000, 1.#INF even for %G). Now they are inf or INF (for %A, %E, %G) with the sign flags, padded with spaces, as C99 specifies; the output on glibc and ucrt does not change. format-19.5 is exact again, new test format-19.6. Tested with a mingw msvcrt build on Windows 11: format.test passes, and fails without this change. NaN cannot get there, it is rejected earlier.

jan.nijtmanswiki2026-10-18 21:07:22

Agreed! Follow-up patch now merged too.

Thanks!

serhiy.storchakawiki2026-10-23 09:32:19

The infinity part of the follow-up [185825858e] was backported to 8.6 in [326e1bf923] for [40f315bc23]. 8.6 has no %a/%A.

Log in (anonymous is fine) to add a comment.