Skip to content

Commit

Permalink
Fix denormal output on own ecvt_r
Browse files Browse the repository at this point in the history
  • Loading branch information
forthy42 committed Oct 16, 2016
1 parent cd0cb9e commit f284053
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions engine/ecvt_r.c
Expand Up @@ -35,7 +35,10 @@ int ecvt_r(double x, int ndigits, int* exp, int* sign, char *buf, size_t len)
if (isnan(x)) {
*sign=0;
*exp=0;
strncpy(buf, "nan", len);
if (x<0)
strncpy(buf, "-na", len);
else
strncpy(buf, "nan", len);
return 0;
}
if (isinf(x)) {
Expand All @@ -59,7 +62,12 @@ int ecvt_r(double x, int ndigits, int* exp, int* sign, char *buf, size_t len)
}

*exp=(x==0)?-1:(int)floor(log10(x));
x = x / pow10((double)*exp);
if(*exp < -300) { /* maybe a denormal: do this in two steps */
x = x * pow10(300.);
x = x / pow10((double)(*exp)+300.);
} else {
x = x / pow10((double)*exp);
}

*exp += 1;

Expand Down

0 comments on commit f284053

Please sign in to comment.