aboutsummaryrefslogtreecommitdiffstats
path: root/printf.c
diff options
context:
space:
mode:
authorMarco Paland <marco@paland.com>2017-11-21 14:52:23 +0100
committerMarco Paland <marco@paland.com>2017-11-21 14:52:23 +0100
commit2b3f3c13067f0f3f061dcfd7b59b925082e72d0d (patch)
tree83cbfaf0f3ce871c9e30021eae10e81f4982a5f3 /printf.c
parentc6c8d964201b26765efa48d9d54467a792759329 (diff)
downloadprintf-2b3f3c13067f0f3f061dcfd7b59b925082e72d0d.tar.gz
printf-2b3f3c13067f0f3f061dcfd7b59b925082e72d0d.tar.bz2
printf-2b3f3c13067f0f3f061dcfd7b59b925082e72d0d.zip
Removed ftoa NaN check
NaN check may not work with optimizing compilers. Use your implementation specific NaN check if necessary
Diffstat (limited to 'printf.c')
-rw-r--r--printf.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/printf.c b/printf.c
index fd29785..83c6d9e 100644
--- a/printf.c
+++ b/printf.c
@@ -214,7 +214,7 @@ static size_t _ntoa_long_long(char* buffer, unsigned long long value, bool negat
static size_t _ftoa(double value, char* buffer, size_t maxlen, unsigned int prec, unsigned int width, unsigned int flags)
{
char buf[FTOA_BUFFER_SIZE];
- size_t len = 0U;
+ size_t len = 0U;
double diff = 0.0;
// if input is larger than thres_max, revert to exponential
@@ -223,10 +223,11 @@ static size_t _ftoa(double value, char* buffer, size_t maxlen, unsigned int prec
// powers of 10
static const double pow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
- // test for NaN
- if (!(value == value) && (maxlen > 2U)) {
- buffer[0] = 'n'; buffer[1] = 'a'; buffer[2] = 'n';
- return (size_t)3U;
+ // test for negative
+ bool negative = false;
+ if (value < 0) {
+ negative = true;
+ value = 0 - value;
}
// limit precision
@@ -238,12 +239,6 @@ static size_t _ftoa(double value, char* buffer, size_t maxlen, unsigned int prec
prec = 9U;
}
- unsigned int negative = 0U;
- if (value < 0) {
- negative = 1U;
- value = 0 - value;
- }
-
int whole = (int)value;
double tmp = (value - whole) * pow10[prec];
unsigned long frac = (unsigned long)tmp;