Skip to content

docs(debt): record the printf floating-point results on firmware 11.60 - #22031

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
xXPBSXx:docs/libc-printf-float-console-1160
Nov 17, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
xXPBSXx:docs/libc-printf-float-console-1160

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

What

The %a and %A and %e, %f and %g entries in docs/dev/debt/libc.md describe this library's own formatter for floating-point conversions, which follows the libc.prx that titles ship, and both say that the result is "not measured on a console". A probe has now called the console's snprintf (libSceLibcInternal.sprx) from a payload process on firmware 11.60 with 46 floating-point cases. The pull request changes the two entries through a debt fragment, as the contribution rules ask, so that each says it was measured on a console in the cases below; no code changes.

The 28 hexadecimal cases are the values 1, 0.5, 1.99951171875, 3.5, DBL_MAX, DBL_MIN and 1 - 2^-53, each with %.3a, %a, %A and %-010.3a (cases a1 to a4, lines 3 to 30). Among them, %.3a of DBL_MAX gave 0x2.000p+1023 and of 1 - 2^-53 gave 0x2.000p-1, a carry that stays in the leading digit as the entry says (lines 15 and 23), %a of DBL_MAX gave 0x1.fffffffffffffp+1023 (line 16), and %-010.3a printed the same text as %.3a, so the - overrides the 0 (for example lines 6 and 10). The 18 decimal cases are %e and %g of 0.1, 1e22, 1e23, 123456789012345678.0 and DBL_MIN (lines 31 to 40), and %f, %.20e, %.0f of 0.5, 1.5 and 2.5 and %.30f of 0.1 and %.1f of 0.25 and 0.35 (lines 41 to 48). Ties go up: %.0f of 0.5, 1.5 and 2.5 gave 1, 2 and 3 (lines 43 to 45), as the entry's "rounds half up" says, and %.30f of 0.1 gave 0.100000000000000005550000000000 (line 46).

The formatter of this library (HexFloat and DecimalFloat in WindowsFormatting.hpp), built into a local test program that is not part of this pull request, gives the same text in all 46 cases. The emulator itself was not run.

Not measured on the console: long double, infinities and NaN, other precisions and flags, widths beyond the cases above, the digits of %f of 1e22 (the entry's remark about about 7% of long outputs ending one unit lower is a statement about the titles' libraries and stays as it is), the wide printf family, and a title process.

Tested

Measured on a PS5 with firmware 11.60 (kernel_get_fw_version 0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr) that loads libSceLibcInternal.sprx and takes snprintf with dlsym, on 2026-11-16 at 23:37 UTC. A title process may differ. The cases are 0 to b3.7, lines 2 to 48 of the raw output in the first comment (line 2 shows that both symbols were found).

Call PS5 payload process, firmware 11.60 AnyPS5 main (formatter run locally) in the entries
28 %a, %A, %.3a, %-010.3a cases texts in lines 3 to 30 same text in all 28 now stated
10 %e and %g cases texts in lines 31 to 40 same text in all 10 now stated
8 %f, %.20e, %.0f, %.30f, %.1f cases texts in lines 41 to 48 same text in all 8 now stated

tools/check_conventions.py --base upstream/main passes with no error and no warning (the %a and %A entry is 896 characters, up from 749, the %e, %f and %g entry 995, up from 937). This is a documentation change, so no test was added or run, and no GPU test applies. Not tested: the emulator against these calls, Linux and macOS formatting, a title process, other firmware, and the cases listed above as not measured.

Overlap: the other open pull requests that change the file of this branch (the fragment docs/dev/debt/changes/docs-libc-printf-float-console-1160.md, a new file), core/libs/prx/libc/include/WindowsFormatting.hpp, which the two entries link, or the two debt entries it changes, found by reading the changed files of all 1611 open pull requests at about 01:36 UTC, by reading what they change in docs/dev/debt/libc.md and in the fragments under docs/dev/debt/changes/ for %a and %A, %e, %f and %g, HexFloat and DecimalFloat, and by searching their titles and branch names for the same names. The branch was test-merged on 2026-11-17 at about 02:03 UTC against main 2354a37269a (the branch is based on 140d6a4546b, an ancestor of it) and merges into it without a conflict; tools/debt_fold.py --check applies the fragment to the libc debt file of main without an error (checked without the fragment libressl3-20171-inventory.md, which already conflicts with feat-libressl3-evp-pkey-new-mac-key-v2.md on main and is not part of this change), the text it changes occurs in exactly one entry each, and no other fragment changes those entries. Three pull requests change WindowsFormatting.hpp: #11332 (fix(libc): bound narrow formatting fields) rewrites HexFloat and DecimalFloat to write into an output object instead of returning a string, #9087 changes the snprintf_s and sscanf_s paths, and #12315 lists the file but changes nothing in it against main; all three already conflict with main without this change and conflict in the same way with it, because this change does not touch the file, so none of them conflicts only with this change, and the 46 cases above were compared against the code on main, not against the rewrite in #11332. About a dozen pull requests that add std::__sce_v2 locale entries to libc.md (for example #16516 and #17610) refer to the %e, %f and %g entry in their own text without changing it, and no open pull request changes either of the two entries. The merged result was not built or run; this is a documentation change.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (documentation only)
  • AI-assisted: yes

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@xXPBSXx

xXPBSXx commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Probe source (built with ps5-payload-sdk v0.45; PROBE_BUILD is the first 12 hex digits of the source's SHA-256, 475039abe417) and its raw output from the run on 2026-11-16 at 23:37 UTC. The clock in the PROBE line is the console's own clock. The probe loads libSceLibcInternal.sprx, takes snprintf with dlsym and formats seven hexadecimal-float values with %.3a, %a, %A and %-010.3a and decimal values with %e, %g, %f, %.20e, %.0f, %.30f and %.1f, printing each text and its length; every call is guarded against signals. The case label 0x1.fffp0 in the raw output names the value 1.99951171875 (hexadecimal 0x1.ffep+0), which is the value the source passes. An internal probe number and case reference in the header comment were removed; the code is unchanged, and the build ID is the hash of the original file.

probe.c
#include <errno.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <ps5/kernel.h>   /* only for kernel_get_fw_version() */

#ifndef PROBE_NAME
#define PROBE_NAME "unnamed"
#endif
#ifndef PROBE_BUILD
#define PROBE_BUILD "unbuilt"
#endif
/* Self limit: on timeout the runner can only close the connection, not end the process on the console.
   The probe ends itself after at most PROBE_MAX_S seconds (the build script sets timeout - 10 s). */
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif

static void probe_alarm(int sig) {
  static const char msg[] = "TIMEOUT\tprobe self limit\n";
  (void)sig;
  (void)!write(1, msg, sizeof msg - 1);
  _exit(124);
}

static int cases = 0;

static void probe_header(void) {
  char utc[32];
  time_t now = time(0);
  struct tm tmv;
  gmtime_r(&now, &tmv);
  strftime(utc, sizeof utc, "%Y-%m-%dT%H:%M:%SZ", &tmv);
  printf("PROBE\t%s\tfw=0x%08x\tbuild=%s\tpid=%d\tutc=%s\n", PROBE_NAME, kernel_get_fw_version(), PROBE_BUILD,
         getpid(), utc);
  fflush(stdout);
}

/* CASE: id, description of the call, return value as long, errno (0 if not set), extra (hex/bytes). */
static void probe_case(const char* id, const char* call, long ret, int err, const char* extra) {
  printf("CASE\t%s\t%s\t%ld\t%d\t%s\n", id, call, ret, err, extra ? extra : "-");
  fflush(stdout);
  cases++;
}

static void probe_end(void) {
  printf("END\t%d\n", cases);
  fflush(stdout);
}

#include <dlfcn.h>
#include <setjmp.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/types.h>

static sigjmp_buf guard_env;
static volatile int guard_sig = 0;
static volatile int guard_active = 0;
static volatile int guard_hits = 0;
static void guard_handler(int s) {
  static const char msg[] = "FAULT\tprobe guard: fault outside a guarded call or too many faults\n";
  if(!guard_active || ++guard_hits > 8) {
    (void)!write(1, msg, sizeof msg - 1);
    _exit(125);
  }
  guard_sig = s;
  guard_active = 0;
  siglongjmp(guard_env, 1);
}
static void guard_arm(void) {
  struct sigaction sa;
  memset(&sa, 0, sizeof sa);
  sa.sa_handler = guard_handler;
  sigaction(SIGSEGV, &sa, 0);
  sigaction(SIGBUS, &sa, 0);
  sigaction(SIGABRT, &sa, 0);
}
#define CALL(rvar, evar, expr) do { errno = 0; guard_sig = 0; rvar = -1; if(sigsetjmp(guard_env, 1) == 0) { guard_active = 1; rvar = (expr); } guard_active = 0; evar = errno; } while(0)

/* printf number formats %a, %A, %e, %f and %g of snprintf of libSceLibcInternal.sprx (dlsym) on firmware 11.60 (
   the entries follow the libc.prx that titles ship, 'checked by running the copies' on a CPU; the system libc of the console may differ). Prototype int
   snprintf(char*, size_t, const char*, ...). Fixed 64 byte buffer, no widths above 40, never %*d. No subnormal input. Group a: %.3a, %a, %A, %-010.3a of
   1.0, 0.5, 0x1.fffp0, 0x1.ffffffffffffep+1023, 0x1p-1022 and a carry case; b: %e %f %g of 0.1, 1e22, 1e23, 123456789012345678.0, 2.2250738585072014e-308,
   %.20e, %.0f of 0.5/1.5/2.5, %.30f of 0.1. The text is printed; 50 calls at most, each guarded. */
#include <math.h>
typedef int (*sp_fn)(char*, size_t, const char*, ...);
static sp_fn sp;
static void fmt(const char* id, const char* what, const char* f, double v) {
  char buf[96];
  memset(buf, 0, sizeof buf);
  int rc, e, r = -99;
  CALL(rc, e, (r = sp(buf, 64, f, v)));
  char ex[180];
  snprintf(ex, sizeof ex, "rc=%d text='%.70s' signal=%d", r, guard_sig ? "-" : buf, (int)guard_sig);
  probe_case(id, what, guard_sig ? -1 : r, e, ex);
}
int main(void) {
  signal(SIGALRM, probe_alarm);
  alarm(PROBE_MAX_S);
  probe_header();
  guard_arm();
  void* hl = dlopen("libSceLibcInternal.sprx", RTLD_LAZY);
  sp = (sp_fn)(hl ? dlsym(hl, "snprintf") : 0);
  char ex[8];
  snprintf(ex, sizeof ex, "%d%d", !!hl, !!sp);
  probe_case("0", "dlopen LibcInternal; dlsym snprintf (1 yes, 0 no)", 0, 0, ex);
  if(!sp) { probe_end(); return 0; }
  static const double av[] = {1.0, 0.5, 1.99951171875, 1.7976931348623157e308, 2.2250738585072014e-308, 1.0 - 1.1102230246251565e-16, 3.5};
  static const char* const an[] = {"1.0", "0.5", "0x1.fffp0", "DBL_MAX", "DBL_MIN", "1-2^-53 (carry)", "3.5"};
  char id[16], w[60];
  for(size_t i = 0; i < sizeof av / sizeof av[0]; i++) {
    snprintf(id, sizeof id, "a1.%zu", i); snprintf(w, sizeof w, "%%.3a of %s", an[i]); fmt(id, w, "%.3a", av[i]);
    snprintf(id, sizeof id, "a2.%zu", i); snprintf(w, sizeof w, "%%a of %s", an[i]); fmt(id, w, "%a", av[i]);
    snprintf(id, sizeof id, "a3.%zu", i); snprintf(w, sizeof w, "%%A of %s", an[i]); fmt(id, w, "%A", av[i]);
    snprintf(id, sizeof id, "a4.%zu", i); snprintf(w, sizeof w, "%%-010.3a of %s", an[i]); fmt(id, w, "%-010.3a", av[i]);
  }
  static const double bv[] = {0.1, 1e22, 1e23, 123456789012345678.0, 2.2250738585072014e-308};
  static const char* const bn[] = {"0.1", "1e22", "1e23", "123456789012345678.0", "DBL_MIN"};
  for(size_t i = 0; i < sizeof bv / sizeof bv[0]; i++) {
    snprintf(id, sizeof id, "b1.%zu", i); snprintf(w, sizeof w, "%%e of %s", bn[i]); fmt(id, w, "%e", bv[i]);
    snprintf(id, sizeof id, "b2.%zu", i); snprintf(w, sizeof w, "%%g of %s", bn[i]); fmt(id, w, "%g", bv[i]);
  }
  fmt("b3.0", "%f of 0.1", "%f", 0.1);
  fmt("b3.1", "%.20e of 0.1", "%.20e", 0.1);
  fmt("b3.2", "%.0f of 0.5", "%.0f", 0.5);
  fmt("b3.3", "%.0f of 1.5", "%.0f", 1.5);
  fmt("b3.4", "%.0f of 2.5", "%.0f", 2.5);
  fmt("b3.5", "%.30f of 0.1", "%.30f", 0.1);
  fmt("b3.6", "%.1f of 0.25", "%.1f", 0.25);
  fmt("b3.7", "%.1f of 0.35", "%.1f", 0.35);
  probe_end();
  return 0;
}
stdout
PROBE	libc_printf_float	fw=0x11600005	build=475039abe417	pid=190	utc=2026-11-17T01:19:47Z
CASE	0	dlopen LibcInternal; dlsym snprintf (1 yes, 0 no)	0	0	11
CASE	a1.0	%.3a of 1.0	10	0	rc=10 text='0x1.000p+0' signal=0
CASE	a2.0	%a of 1.0	6	0	rc=6 text='0x1p+0' signal=0
CASE	a3.0	%A of 1.0	6	0	rc=6 text='0X1P+0' signal=0
CASE	a4.0	%-010.3a of 1.0	10	0	rc=10 text='0x1.000p+0' signal=0
CASE	a1.1	%.3a of 0.5	10	0	rc=10 text='0x1.000p-1' signal=0
CASE	a2.1	%a of 0.5	6	0	rc=6 text='0x1p-1' signal=0
CASE	a3.1	%A of 0.5	6	0	rc=6 text='0X1P-1' signal=0
CASE	a4.1	%-010.3a of 0.5	10	0	rc=10 text='0x1.000p-1' signal=0
CASE	a1.2	%.3a of 0x1.fffp0	10	0	rc=10 text='0x1.ffep+0' signal=0
CASE	a2.2	%a of 0x1.fffp0	10	0	rc=10 text='0x1.ffep+0' signal=0
CASE	a3.2	%A of 0x1.fffp0	10	0	rc=10 text='0X1.FFEP+0' signal=0
CASE	a4.2	%-010.3a of 0x1.fffp0	10	0	rc=10 text='0x1.ffep+0' signal=0
CASE	a1.3	%.3a of DBL_MAX	13	0	rc=13 text='0x2.000p+1023' signal=0
CASE	a2.3	%a of DBL_MAX	23	0	rc=23 text='0x1.fffffffffffffp+1023' signal=0
CASE	a3.3	%A of DBL_MAX	23	0	rc=23 text='0X1.FFFFFFFFFFFFFP+1023' signal=0
CASE	a4.3	%-010.3a of DBL_MAX	13	0	rc=13 text='0x2.000p+1023' signal=0
CASE	a1.4	%.3a of DBL_MIN	13	0	rc=13 text='0x1.000p-1022' signal=0
CASE	a2.4	%a of DBL_MIN	9	0	rc=9 text='0x1p-1022' signal=0
CASE	a3.4	%A of DBL_MIN	9	0	rc=9 text='0X1P-1022' signal=0
CASE	a4.4	%-010.3a of DBL_MIN	13	0	rc=13 text='0x1.000p-1022' signal=0
CASE	a1.5	%.3a of 1-2^-53 (carry)	10	0	rc=10 text='0x2.000p-1' signal=0
CASE	a2.5	%a of 1-2^-53 (carry)	20	0	rc=20 text='0x1.fffffffffffffp-1' signal=0
CASE	a3.5	%A of 1-2^-53 (carry)	20	0	rc=20 text='0X1.FFFFFFFFFFFFFP-1' signal=0
CASE	a4.5	%-010.3a of 1-2^-53 (carry)	10	0	rc=10 text='0x2.000p-1' signal=0
CASE	a1.6	%.3a of 3.5	10	0	rc=10 text='0x1.c00p+1' signal=0
CASE	a2.6	%a of 3.5	8	0	rc=8 text='0x1.cp+1' signal=0
CASE	a3.6	%A of 3.5	8	0	rc=8 text='0X1.CP+1' signal=0
CASE	a4.6	%-010.3a of 3.5	10	0	rc=10 text='0x1.c00p+1' signal=0
CASE	b1.0	%e of 0.1	12	0	rc=12 text='1.000000e-01' signal=0
CASE	b2.0	%g of 0.1	3	0	rc=3 text='0.1' signal=0
CASE	b1.1	%e of 1e22	12	0	rc=12 text='1.000000e+22' signal=0
CASE	b2.1	%g of 1e22	5	0	rc=5 text='1e+22' signal=0
CASE	b1.2	%e of 1e23	12	0	rc=12 text='1.000000e+23' signal=0
CASE	b2.2	%g of 1e23	5	0	rc=5 text='1e+23' signal=0
CASE	b1.3	%e of 123456789012345678.0	12	0	rc=12 text='1.234568e+17' signal=0
CASE	b2.3	%g of 123456789012345678.0	11	0	rc=11 text='1.23457e+17' signal=0
CASE	b1.4	%e of DBL_MIN	13	0	rc=13 text='2.225074e-308' signal=0
CASE	b2.4	%g of DBL_MIN	12	0	rc=12 text='2.22507e-308' signal=0
CASE	b3.0	%f of 0.1	8	0	rc=8 text='0.100000' signal=0
CASE	b3.1	%.20e of 0.1	26	0	rc=26 text='1.00000000000000005550e-01' signal=0
CASE	b3.2	%.0f of 0.5	1	0	rc=1 text='1' signal=0
CASE	b3.3	%.0f of 1.5	1	0	rc=1 text='2' signal=0
CASE	b3.4	%.0f of 2.5	1	0	rc=1 text='3' signal=0
CASE	b3.5	%.30f of 0.1	32	0	rc=32 text='0.100000000000000005550000000000' signal=0
CASE	b3.6	%.1f of 0.25	3	0	rc=3 text='0.3' signal=0
CASE	b3.7	%.1f of 0.35	3	0	rc=3 text='0.3' signal=0
END	47

AI-assisted (Claude Code).

@github-actions github-actions Bot added the docs label Nov 17, 2026
@oneandonlydean
oneandonlydean merged commit c182c06 into boykopovar:main Nov 17, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants