Skip to content

Convert numbers assigned to FS, OFS, SUBSEP and others with CONVFMT - #674

Merged
bertysentry merged 5 commits into
mainfrom
feature/issue-672-special-var-convfmt
Nov 27, 2026
Merged

bertysentry merged 5 commits into
mainfrom
feature/issue-672-special-var-convfmt

Conversation

@bertysentry

@bertysentry bertysentry commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #672

Summary

JRT.setFS(), setRS(), setOFS(), setORS(), setSUBSEP(), setCONVFMT() and setOFMT() stored value.toString(), so a Double assigned to these variables got Java's formatting. They now use toAwkString(), the same CONVFMT conversion used for concatenation, which prints an integral value as an integer. All assignment paths (ASSIGN_* opcodes, -v, Java settings) go through these setters.

The variables still hold the value assigned to them (so FS = 3.6 reads back as 3.6 even with a lossy CONVFMT, as in gawk), and settings apply CONVFMT before the other special variables.

BEGIN { OFS = 0.1 + 0.2; print "a", "b"; OFS = 3; OFS++; print "a", "b"; SUBSEP = 2 / 2.0; SUBSEP += 0; a[1, 2]; for (k in a) print k }
Output
Before a0.30000000000000004b / a4.0b / 11.02
After (= gawk) a0.3b / a4b / 112

Tests

  • New SpecialVariableConversionTest (via AwkTestSupport) covers all seven variables; expected outputs checked against gawk.
  • mvn verify: unit tests pass, checkstyle/PMD/SpotBugs clean; the compatibility IT failures are identical to main.
  • Bullet added under Unreleased in behavior-changes.md.

🤖 Generated with Claude Code

The setters of FS, RS, OFS, ORS, SUBSEP, CONVFMT and OFMT stored
value.toString(), so a Double such as 0.1 + 0.2 or the result of OFS++
got Java's formatting (0.30000000000000004, 4.0). They now convert the
value with toAwkString(), which applies CONVFMT and prints an integral
value as an integer, as gawk does.

Fixes #672

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T16:59:42.363288Z fe4b59a Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 259d41382e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main/java/io/jawk/jrt/JRT.java Resolved
Comment thread src/main/java/io/jawk/jrt/JRT.java Resolved
A special variable stored as text now keeps the value assigned to it,
so FS = 3.6 still reads as 3.6 after a lossy CONVFMT, as in gawk, while
the separator and format operations use the text converted when it was
assigned. Settings apply CONVFMT before the other special variables, so
a numeric RS or SUBSEP given next to a custom CONVFMT uses that format.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bertysentry

Copy link
Copy Markdown
Contributor Author

@codex please review again

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c1f4eead5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main/java/io/jawk/jrt/JRT.java Resolved
Comment thread src/main/java/io/jawk/jrt/JRT.java Resolved
Comment thread src/main/java/io/jawk/jrt/JRT.java Resolved
- The JRT constructor sets the values of FS, OFS and the other text
  specials to their defaults, so they read as before execution starts.
- assignInitialVariables() goes through applySpecialVariables(), so
  CONVFMT is applied first there too.
- Settings and per-run overrides of special variables are normalized
  like other variables, so a BigDecimal or BigInteger keeps its text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bertysentry

Copy link
Copy Markdown
Contributor Author

@codex please review again

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c5a850f08a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main/java/io/jawk/jrt/JRT.java Resolved
The setters of FS, OFS and the other text specials turn a BigDecimal
or BigInteger into a numeric string that keeps its digits, as the AVM
does for any host variable, instead of converting it through a double.
This covers direct calls and assignInitialVariables(), so the separate
normalization of the special-variable maps in the AVM is dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bertysentry

Copy link
Copy Markdown
Contributor Author

@codex please review again

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8c31b9e99b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main/java/io/jawk/jrt/JRT.java Resolved
Comment thread src/main/java/io/jawk/jrt/JRT.java Resolved
The special-variable setters now use StrNum.ofJavaNumber() for a
BigDecimal or BigInteger, so its period stays a decimal point in a
locale with a decimal comma, and turn a Boolean into AWK's 1 or 0, as
applySpecialVariable() and the AVM already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bertysentry

Copy link
Copy Markdown
Contributor Author

@codex please review again

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: fe4b59af91

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@bertysentry
bertysentry merged commit e46d5e5 into main Nov 27, 2026
5 checks passed
@bertysentry
bertysentry deleted the feature/issue-672-special-var-convfmt branch November 27, 2026 17:06
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.

A number assigned to FS, OFS, SUBSEP and other special variables is converted with toString(), not CONVFMT

1 participant