Format infinity.

This commit is contained in:
Victor Zverovich
2012-12-29 06:44:14 -08:00
parent 529045b65d
commit 4762a8afd0
3 changed files with 30 additions and 6 deletions
+16 -1
View File
@@ -141,7 +141,7 @@ int signbit(double value) {
if (value < 0) return 1;
if (value == value) return 0;
int dec = 0, sign = 0;
ecvt(value, 0, &dec, &sign);
_ecvt(value, 0, &dec, &sign);
return sign;
}
#endif
@@ -337,6 +337,21 @@ void Formatter::FormatDouble(T value, const FormatSpec &spec, int precision) {
return;
}
if (isinf(value)) {
// Format infinity ourselves because sprintf's output is not consistent
// across platforms.
std::size_t size = 4;
const char *inf = upper ? " INF" : " inf";
if (!sign) {
--size;
++inf;
}
char *out = FormatString(inf, size, spec);
if (sign)
*out = sign;
return;
}
size_t offset = buffer_.size();
unsigned width = spec.width;
if (sign) {