Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-add the npf_inline qualifier #268

Merged
merged 3 commits into from
Jun 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions nanoprintf.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* nanoprintf v0.5.0: a tiny embeddable printf replacement written in C.
/* nanoprintf v0.5.1: a tiny embeddable printf replacement written in C.
https://github.com/charlesnicholson/nanoprintf
charles.nicholson+nanoprintf@gmail.com
dual-licensed under 0bsd and unlicense, take your pick. see eof for details. */
Expand Down Expand Up @@ -474,7 +474,8 @@ static int npf_parse_format_spec(char const *format, npf_format_spec_t *out_spec
return (int)(cur - format);
}

static int npf_utoa_rev(npf_uint_t val, char *buf, uint_fast8_t base, char case_adj) {
static NPF_NOINLINE int npf_utoa_rev(
npf_uint_t val, char *buf, uint_fast8_t base, char case_adj) {
uint_fast8_t n = 0;
do {
int_fast8_t const d = (int_fast8_t)(val % base);
Expand All @@ -489,15 +490,15 @@ static int npf_utoa_rev(npf_uint_t val, char *buf, uint_fast8_t base, char case_

#include <float.h>

#if (DBL_MANT_DIG <= 11) && (DBL_MAX_EXP <= 16)
typedef uint_fast16_t npf_double_bin_t;
typedef int_fast8_t npf_ftoa_exp_t;
#if (DBL_MANT_DIG <= 11) && (DBL_MAX_EXP <= 16)
typedef uint_fast16_t npf_double_bin_t;
typedef int_fast8_t npf_ftoa_exp_t;
#elif (DBL_MANT_DIG <= 24) && (DBL_MAX_EXP <= 128)
typedef uint_fast32_t npf_double_bin_t;
typedef int_fast8_t npf_ftoa_exp_t;
typedef uint_fast32_t npf_double_bin_t;
typedef int_fast8_t npf_ftoa_exp_t;
#elif (DBL_MANT_DIG <= 53) && (DBL_MAX_EXP <= 1024)
typedef uint_fast64_t npf_double_bin_t;
typedef int_fast16_t npf_ftoa_exp_t;
typedef uint_fast64_t npf_double_bin_t;
typedef int_fast16_t npf_ftoa_exp_t;
#else
#error Unsupported width of the double type.
#endif
Expand All @@ -524,15 +525,15 @@ enum {
((NPF_FTOA_MAN_BITS < DBL_MANT_DIG) ? NPF_FTOA_MAN_BITS : DBL_MANT_DIG) - 1
};

/* Generally floating-point conversion implementations use
/* Generally, floating-point conversion implementations use
grisu2 (https://bit.ly/2JgMggX) and ryu (https://bit.ly/2RLXSg0) algorithms,
which are mathematically exact and fast, but require large lookup tables.

This implementation was inspired by Wojciech Muła's (zdjęcia@garnek.pl)
algorithm (http://0x80.pl/notesen/2015-12-29-float-to-string.html) and
extended further by adding dynamic scaling and configurable integer width by
Oskars Rubenis (https://github.com/Okarss).
*/
Oskars Rubenis (https://github.com/Okarss). */

static int npf_ftoa_rev(char *buf, npf_format_spec_t const *spec, double f) {
char const *ret = NULL;
npf_double_bin_t bin; { // Union-cast is UB pre-C11, compiler optimizes byte-copy loop.
Expand Down