Skip to content

stdio/format: fix printing sign for long double#487

Open
rmikielis wants to merge 1 commit into
masterfrom
rmikielis/printf_fix_minors
Open

stdio/format: fix printing sign for long double#487
rmikielis wants to merge 1 commit into
masterfrom
rmikielis/printf_fix_minors

Conversation

@rmikielis

@rmikielis rmikielis commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

JIRA: RTOS-1368

Description

When down-converting from long double to double on RISCV, GCC is emitting __trunctfdf2() which truncates sign bit for special values (NaN, inf). This fix preservers sign bit before down-convertion, and adds it later when needed.

Motivation and Context

Fixes phoenix-rtos/phoenix-rtos-project#1007

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (list targets here).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates stdio/format.c to preserve the sign bit when downconverting a long double to a double during floating-point formatting. It introduces an msb parameter to format_sprintfDouble to pass the sign bit. A review comment correctly points out that checking the sign bit with __builtin_signbit(doubleNumber) > 0 is unsafe, as the function is only guaranteed to return a non-zero value which could be negative on some platforms. It is recommended to use != 0 instead.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread stdio/format.c Outdated
@rmikielis rmikielis force-pushed the rmikielis/printf_fix_minors branch from b3bfc24 to af61ddc Compare June 25, 2026 13:21
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown

Unit Test Results

10 860 tests  ±0   10 190 ✅ ±0   53m 37s ⏱️ + 1m 45s
   670 suites ±0      670 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit 3bcf8eb. ± Comparison against base commit 8ff4671.

♻️ This comment has been updated with latest results.

@rmikielis rmikielis force-pushed the rmikielis/printf_fix_minors branch from af61ddc to 65b9b02 Compare June 26, 2026 09:59
@rmikielis rmikielis requested a review from a team June 26, 2026 10:00
@rmikielis rmikielis force-pushed the rmikielis/printf_fix_minors branch from 65b9b02 to 3bcf8eb Compare June 26, 2026 10:05
@rmikielis rmikielis marked this pull request as ready for review June 26, 2026 10:18
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.

riscv64: incorrect formatting of long double "-nan" with printf functions

1 participant