Skip to content
Open
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
12 changes: 12 additions & 0 deletions lib/print/printf_tiny.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
#include <float.h>
#endif

#if defined(PRINTF_SUPPORT_LONG_LONG) && defined(PRINTF_SUPPORT_EXPONENTIAL)
#include <math.h>
#include <limits.h>
#endif

// output function type
typedef void (*out_fct_type)(char character, void* buffer, size_t idx, size_t maxlen);

Expand Down Expand Up @@ -523,6 +528,13 @@ static size_t _etoa(
prec = PRINTF_DEFAULT_FLOAT_PRECISION;
}

// if value is a whole number, print it using %ll method
#if defined(PRINTF_SUPPORT_LONG_LONG)
if(flags & FLAGS_ADAPT_EXP && value < nextafter(ULONG_LONG_MAX, 1) && value == floor(value)) {
return _ntoa_long_long(out, buffer, idx, maxlen, value, negative, 10, 0, width, flags);
}
#endif

// determine the decimal exponent
// based on the algorithm by David Gay (https://www.ampl.com/netlib/fp/dtoa.c)
union {
Expand Down