Commit fbfedcf0 authored by Victor Zverovich's avatar Victor Zverovich

Fix the issue with signbit in C++11.

parent 446f22fb
...@@ -31,10 +31,16 @@ ...@@ -31,10 +31,16 @@
#undef _SCL_SECURE_NO_WARNINGS #undef _SCL_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS #define _SCL_SECURE_NO_WARNINGS
#include "format.h"
#include <math.h> #include <math.h>
// Wrap signbit because when compiled in C++11 mode signbit is no longer a
// macro but a function defined in namespace std and the macro is undefined.
#ifndef _MSC_VER
inline int SignBit(double value) { return signbit(value); }
#endif
#include "format.h"
#include <cassert> #include <cassert>
#include <cctype> #include <cctype>
#include <climits> #include <climits>
...@@ -85,7 +91,7 @@ char *FillPadding(char *buffer, ...@@ -85,7 +91,7 @@ char *FillPadding(char *buffer,
} }
#ifdef _MSC_VER #ifdef _MSC_VER
int signbit(double value) { int SignBit(double value) {
if (value < 0) return 1; if (value < 0) return 1;
if (value == value) return 0; if (value == value) return 0;
int dec = 0, sign = 0; int dec = 0, sign = 0;
...@@ -188,9 +194,9 @@ void BasicFormatter::FormatDouble( ...@@ -188,9 +194,9 @@ void BasicFormatter::FormatDouble(
} }
char sign = 0; char sign = 0;
// Use signbit instead of value < 0 because the latter is always // Use SignBit instead of value < 0 because the latter is always
// false for NaN. // false for NaN.
if (signbit(value)) { if (SignBit(value)) {
sign = '-'; sign = '-';
value = -value; value = -value;
} else if (spec.sign_flag()) { } else if (spec.sign_flag()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment