[sprintf] Non standard nan/inf capitalization

Open
#29 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
c
Domain
devtools

Research direction

The work is in stb_sprintf.h. Start with the format-specifier parsing near line 628, where the flag characters are read, and then the nan/inf branch near lines 805-810, where the aA/eE/gG case adjustment already happens. Add the uppercase F specifier so it produces INF, INFINITY, or NAN, and check that lowercase f output is unchanged. Done when %F formats infinities and NaNs in uppercase and the lowercase behaviour still matches the C standard.

Written by the indexing model from the issue text.

Description

The standard states:

A double argument representing an infinity is converted in one of the styles [-]inf or [-]infinity—which style is implementation-defined. A double argument representing a NaN is converted in one of the styles [-]nan or [-]nan(n-char-sequence) — which style, and the meaning of any n-char-sequence, is implementation-defined. The F conversion specifier produces INF, INFINITY, or NAN instead of inf, infinity, or nan, respectively.

STB prints nan as "NaN" and inf as "Inf".
It would be better if it respected the proper case.
Also, STB does not understand the 'F' flag, which is just like 'f', but with uppercase representations for nan/inf.
This could easily be added here:
https://github.com/nothings/stb/blob/f0569113c93ad095470c54bf34a17b36646bbbb5/stb_sprintf.h#L628
just to ignore it; and here:
https://github.com/nothings/stb/blob/f0569113c93ad095470c54bf34a17b36646bbbb5/stb_sprintf.h#L805-L810
with an added case adjustment just like is done for aA eE gG:

h = (f[0] == 'F') ? hexu : hex;
Dominant language
C
Stars
18
Forks
5
Avg merge
1m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nothings/stb_sprintf

All issues in nothings/stb_sprintf

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.