Skip to content

Fix: correct %g significant digit handling and update test#980

Open
peripherium wants to merge 1 commit intoksh93:devfrom
peripherium:fix/sfcvt-digit-limit
Open

Fix: correct %g significant digit handling and update test#980
peripherium wants to merge 1 commit intoksh93:devfrom
peripherium:fix/sfcvt-digit-limit

Conversation

@peripherium
Copy link
Copy Markdown

_sfcvt() incorrectly limited n_digit based on the number of digits before the decimal point, causing printf("%.Ng") to emit fewer than N significant digits for large values.

Adjust n_digit to depend solely on the requested precision and only truncate when the underlying buffer does not provide enough digits. This restores correct %g semantics.

Update the corresponding test to use typeset -lE (SFFMT_LDOUBLE) instead of -E. The previous test passed unintentionally because the truncation masked precision differences. The tested number of significant digits requires double precision to produce reliable results.

Fixes #952

_sfcvt() incorrectly limited n_digit based on the number of digits
before the decimal point, causing printf("%.Ng") to emit fewer than
N significant digits for large values.

Adjust n_digit to depend solely on the requested precision and only
truncate when the underlying buffer does not provide enough digits.
This restores correct %g semantics.

Update the corresponding test to use typeset -lE (SFFMT_LDOUBLE)
instead of -E. The previous test passed unintentionally
because the truncation masked precision differences. The tested
number of significant digits requires double precision to produce
reliable results.

Fixes ksh93#952
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.

Weird truncation with printf %g

1 participant