fix(libc): return +0 from strtod when nothing is converted #3613

Closed
karim200003 wants to merge 1 commit from upstream-pr/3613 into main
karim200003 commented 2026-10-11 14:15:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by karim200003 on 2026-10-11T14:15:12Z.


The guest strtod, strtof, strtold, atof and the wide variants passed straight through to the host. When a sign is not followed by a number ("-", "-.", "-x", "-.e1", "-e5") nothing is consumed and the Windows runtime returns -0.0. FreeBSD's gdtoa strtod and strtodg clear the sign on their ret0 path and return +0.0 with the end pointer at the input; glibc already does the same.

The narrow functions now return +0 whenever the host consumed nothing, detected from their own end pointer so a null endptr works too, and leave every real conversion alone, so "-0", "-.0", "-0e5" and "-0x0p0" keep their sign. The wide functions parse through the narrow ones, and atof is strtod(str, NULL) as in FreeBSD.

guest_math and guest_wide_strings check the no-conversion shapes for all six functions, with and without endptr, and the -0 conversions that must stay negative.

Fixes #3090

AI-assisted: yes

What

Tested

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 in TechnicalDebt
  • 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:
  • AI-assisted:
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4819694399 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3613). Originally posted by [karim200003](https://github.com/karim200003) on 2026-10-11T14:15:12Z. --- The guest strtod, strtof, strtold, atof and the wide variants passed straight through to the host. When a sign is not followed by a number ("-", "-.", "-x", "-.e1", "-e5") nothing is consumed and the Windows runtime returns -0.0. FreeBSD's gdtoa strtod and strtodg clear the sign on their ret0 path and return +0.0 with the end pointer at the input; glibc already does the same. The narrow functions now return +0 whenever the host consumed nothing, detected from their own end pointer so a null endptr works too, and leave every real conversion alone, so "-0", "-.0", "-0e5" and "-0x0p0" keep their sign. The wide functions parse through the narrow ones, and atof is strtod(str, NULL) as in FreeBSD. guest_math and guest_wide_strings check the no-conversion shapes for all six functions, with and without endptr, and the -0 conversions that must stay negative. Fixes #3090 AI-assisted: yes ### What ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [ ] 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [ ] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [ ] 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: <!-- #PR, or none --> - [ ] AI-assisted: <!-- yes / no -->
github-actions[bot] commented 2026-10-11 14:15:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T14:15:23Z.


Thank you for your contribution! Authors with no pull requests merged into main can have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109937517 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3613#issuecomment-6109937517). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T14:15:23Z. --- Thank you for your contribution! Authors with no pull requests merged into `main` can have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!3613
No description provided.