[RFC]: replace inline NaN generation with stdlib NaN constants in C source files (tracking issue)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 58/100
- Tipo di issue
- Refactoring
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- c
- Ambito
- build-system, testing
Direzione di ricerca
Esamina le PR #11768 e #11769, quindi cerca 0.0f?\s*/\s*0.0f? per selezionare un package non ancora coperto. Ispeziona il suo src/main.c, examples/c/example.c, benchmark/c/benchmark.c, README.md e manifest.json; il lavoro è completato quando la macro NaN pertinente, l’include e le dipendenze sono aggiornati solo lì. Esegui i comandi specificati dell’add-on, dell’esempio C, del benchmark e dei test per quel package e conferma che l’output non è cambiato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Instructions
- Read the issue description below.
- Review the example pull requests linked below.
- Search the codebase for a package containing inline NaN generation in a C source file and update it according to this issue.
- Follow all additional guidance in this issue.
Description
This RFC proposes replacing inline NaN generation (e.g., 0.0/0.0 or 0.0f/0.0f) in C source files, examples, benchmarks, and README C usage snippets with the stdlib NaN constant from @stdlib/constants/float64/nan or @stdlib/constants/float32/nan.
In short, this RFC seeks to refactor code from this pattern:
return 0.0/0.0; // NaN
to this pattern:
#include "stdlib/constants/float64/nan.h"
// ...
return STDLIB_CONSTANT_FLOAT64_NAN;
This refactoring is demonstrated in PR #11768 (float64) and PR #11769 (float32). Study both PRs before starting, as they demonstrate the exact changes being sought.
In particular, notice three things:
- We add the C header include for the NaN constant:
#include "stdlib/constants/float64/nan.h". - We replace inline NaN generation with the macro
STDLIB_CONSTANT_FLOAT64_NAN. - We add the dependency
@stdlib/constants/float64/nanto all manifest configuration entries (build,benchmark,examples) which compile the updated C source file.
By performing this refactoring, we facilitate:
- Consistent NaN handling across packages and targets.
- Better readability and maintainability in C implementations.
Float32
There are also inline float32 NaN occurrences written as 0.0f/0.0f which must be replaced with STDLIB_CONSTANT_FLOAT32_NAN from @stdlib/constants/float32/nan. The equivalent include is #include "stdlib/constants/float32/nan.h" and the manifest dependency is @stdlib/constants/float32/nan. The float32 migration is demonstrated in PR #11769.
Steps
-
Study the changes in PR #11768 (float64) and PR #11769 (float32), as these demonstrate the exact changes being sought.
-
Ensure your local development environment is set up by following the contributing guide, including running
make install-node-modulesandmake init. -
Find a package containing inline NaN generation in a C source file. A possible global project search can use the following regular expression:
0\.0f?\s*/\s*0\.0f?From the search results, locate a package not already addressed by an open or merged PR referencing this issue.
-
Update that package, and only that package, to use
STDLIB_CONSTANT_FLOAT64_NAN(orSTDLIB_CONSTANT_FLOAT32_NANfor float32). Updated files may includesrc/main.c,examples/c/example.c,benchmark/c/benchmark.c, and any C code snippets inREADME.md. -
When adding the
#includestatement, place it with the existing stdlib includes in the file, following the include ordering already present. Do not reorder existing includes. -
Update
manifest.jsonto add the NaN constant package as a dependency in everyconfsentry that compiles the updated C source file. This typically includes thebuild,benchmark, andexamplestask entries. For example (float64 shown; use@stdlib/constants/float32/nanfor float32 packages):{ "task": "build", "src": [ "./src/main.c" ], "include": [ "./include" ], "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/some/existing/dep" + "@stdlib/some/existing/dep", + "@stdlib/constants/float64/nan" ] } -
Also check the package
README.mdfor any C usage examples containing0.0/0.0or0.0f/0.0fand update those to use the macro as well. -
Build the Node add-on and run the C examples, benchmarks, and native tests using the commands below. Replace
<package-path>with the path of the package you updated (e.g.,stats/strided/dnanmeanpn):cd /path/to/stdlib # Build the Node add-on for the specific package make install-node-addons NODE_ADDONS_PATTERN="<package-path>" # Run C examples, benchmarks, and native tests make EXAMPLES_FILTER=".*/<package-path>/.*" examples-c make BENCHMARKS_FILTER=".*/<package-path>/.*" benchmark-c make test TESTS_FILTER=".*/<package-path>/.*"Verify that the test and example output after refactoring is identical to what it was before (i.e.,
NaNis returned wherever expected). No behavioral changes should result from this refactor. -
Before opening a PR, search existing open pull requests that reference this issue to confirm no one has already submitted the same package.
-
Commit your changes and submit a PR updating only that package.
-
Use the appropriate PR title template based on which constant you replaced:
For float64 packages:
refactor: use `constants/float64/nan` in <package-name>For float32 packages:
refactor: use `constants/float32/nan` in <package-name> -
In the PR body, use the phrase "Resolves a part of" followed by a link to this issue. Do not use "Resolves" or "Closes", as this is a tracking issue and your PR only addresses one package of many.
Related Issues
None.
Questions
None.
Other
- For each pull request, please update only one package.
- Do not make unrelated or stylistic changes. Only replace inline NaN generation with the shared NaN constant and make the required dependency and include updates. Failure to respect this guidance will result in your PR being closed without review.
- Before opening a PR, verify that no existing open PR already addresses the same package by searching pull requests that reference this issue.
- As this is a Good First Issue, you are strongly encouraged to avoid using AI when authoring your contribution. One of the primary intents of Good First Issues is to help introduce you to stdlib, its development environment, and the contribution process, as documented in the contributing guide. Most new contributors are unfamiliar with stdlib and its conventions, and thus fail to appropriately use AI assistance, most often generating low-quality output that leads to wasted time for everyone involved. Take the time to manually author your first several PRs, and once you are intimately familiar with project conventions, you can consider leveraging AI to augment your development tasks.
Checklist
- I have read and understood the Code of Conduct.
- I have searched for existing issues and pull requests.
- The issue title begins with
RFC:.
- Lingua principale
- JavaScript
- Stelle
- 6k
- Fork
- 1.3k
- Merge medio
- 1g 3h
- PR unite (30g)
- 567
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di stdlib-js/stdlib
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: rayleigh/mgf returns wrong values due to misplaced parenthesisForse già presa @anandkaranubc l’ha presa 2 giorni fa. ApertaBug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
stdlib-js/stdlib#15456 · 6 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
stdlib-js/stdlib#15193 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Fix JavaScript lint errorsApertaGood First Issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
stdlib-js/stdlib#14759 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Fix C lint errorsAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di stdlib-js/stdlib
Issue simili
-
bug CI breakage triage needed
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
oppia/oppia#27517 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
draftomen enhancement size: S
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
andreagrandi/draftomen#761 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
HarperFast/harper#2866 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
HarperFast/harper-pro#927 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
anthropics/skills#1897 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno