Skip to content

[RFC]: Replace inline 0.0/0.0 occurences in C source files with STDLIB_CONSTANT_FLOAT64_NAN from @stdlib/constants/float64/nan #11743

@manit2004

Description

@manit2004

Instructions

  1. Read the issue description below.
  2. Review the example pull request linked below.
  3. Find one package containing inline NaN generation in a C source file (for example, 0.0/0.0) and update it according to this issue.
  4. Follow all additional guidance in this issue.

Description

This RFC proposes replacing inline NaN generation in C source files (for example, 0.0/0.0) with the shared stdlib NaN constant from @stdlib/constants/float64/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;

The migration is demonstrated in this PR commit 000785d

In particular, notice three things:

  1. We add the C header include for the NaN constant.
  2. We replace inline NaN generation with STDLIB_CONSTANT_FLOAT64_NAN.
  3. We add the dependency @stdlib/constants/float64/nan to manifest configuration entries which compile that same C source file (typically build, benchmark, and examples, when applicable).

By performing this refactoring, we facilitate:

  1. Consistent NaN handling across packages and targets.
  2. Better readability and maintainability in C implementations.

Steps

Given the relatively widespread use of inline NaN generation, this RFC is an open call for contributors to do the following:

  1. Study the example PR commit linked above, as it demonstrates the changes we are seeking.
  2. Ensure your local development environment is set up by following the contributing guide
  3. Find one package containing inline NaN generation in C source files.
  4. Update that package, and only that package, to use STDLIB_CONSTANT_FLOAT64_NAN from @stdlib/constants/float64/nan.
  5. Add the include statement for stdlib/constants/float64/nan.h in updated C sources.
  6. Update the package manifest dependencies for all task configurations that compile the updated source file.
  7. Run relevant checks for the package you changed.
  8. Commit your changes.
  9. Submit a PR updating that package only.
  10. Use this PR title template:
    refactor: use constants/float64/nan in < package-name >
  11. In the PR body, use the phrase Resolves a part of , and not Resolves or Closes, because this is a tracking issue.

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 required dependency updates.
  • As this is a Good First Issue, contributors are strongly encouraged to avoid AI for their first contributions and to follow existing project conventions closely.

Checklist

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions