Skip to content

Spec 033 T004: floats as JDK 11's Float.toString writes them - #1124

Merged
adamjohnwright merged 1 commit into
mainfrom
spec033/t004-java-float
Nov 28, 2026
Merged

adamjohnwright merged 1 commit into
mainfrom
spec033/t004-java-float

Conversation

@adamjohnwright

Copy link
Copy Markdown
Contributor

Spec 033 T004.

Why it's needed: miscore writes each MI-score with Float.toString and reads it back with Double.parseDouble (research-psicquic.md §6). So the score Java filters at 0.45 and rounds is the double of that text, not the float itself.

What it adds:

  • tools/content-node/java-float.ts:
    • jdk11FloatText(value) gives the text JDK 11's Float.toString writes for the float nearest value;
    • throughFloatText(value) gives miscore's round trip.
  • java-double.ts shares its digit generation (floatingDecimalDigits, layOut). JDK 11 writes a float through the same FloatingDecimal steps as a double: the float's 23-bit fraction is moved up to bit 52 and developed with a precision of 24. So the logic is shared, not copied. java-double.spec.ts still passes unchanged.

Measured against JDK 11 itself. The deployed service runs on JDK 11, so that's the JDK that matters. JDK 19 and later write the shortest form, so they're no reference here.

  • The comparison: a small Java program, compiled with --release 11 and run on JDK 11.0.33, streamed 12,507,903 floats into a node checker. They were every 997th bit pattern, 8 million random ones, and k / 100,000 for k from 0 to 100,000. None differ.
  • Non-shortest: 1,330,237 of those floats (about 1 in 10) are written with more digits than the shortest form. JavaScript's own formatting would have got all of those wrong.
  • The fixture (fixtures/java-float.txt) keeps 4,009 of them: the specials and boundaries, every decimal score from 0 to 1 at three places, and 1,500 non-shortest and 1,500 shortest others.

Seen failing:

  • giving floats a double's precision (53) fails 8 tests;
  • writing JavaScript's shortest form fails 11.

Both mutants were restored from a copy.

One part of the task not done here: it asked for single-precision steps. JavaScript's Math.fround already gives them exactly, so no wrapper is added; the score port (T009) uses it directly. tasks.md says so.

🤖 Generated with Claude Code

miscore writes each score with Float.toString and reads it back as a
double, so the score Java filters and rounds is that text's double.
JDK 11 writes a float through the same FloatingDecimal steps as a
double (its fraction moved up to bit 52, a precision of 24), so
java-double.ts's digit generation is now shared, not copied.

Compared with JDK 11 itself, the JDK the deployed service runs on, over
12,507,903 floats: none differ, and 1,330,237 of them are not in the
shortest form, which JavaScript's own text would have written. The
fixture keeps 4,009, with every decimal score between 0 and 1. The spec
fails with a double's precision (8 tests) and with JavaScript's
shortest form (11 tests).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adamjohnwright
adamjohnwright merged commit 846333b into main Nov 28, 2026
13 checks passed
@adamjohnwright
adamjohnwright deleted the spec033/t004-java-float branch November 28, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant