summaryrefslogtreecommitdiff
path: root/src/mongo/bson
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2015-02-03 18:40:35 -0500
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2015-02-05 13:53:16 -0500
commit93e72f29f5d58dff1229c8db9db62b4f02324117 (patch)
tree975970f00278485ab112767e2758d290da588665 /src/mongo/bson
parent68fe6570d19c744f84861b70d541e8b46ac24935 (diff)
downloadmongo-93e72f29f5d58dff1229c8db9db62b4f02324117.tar.gz
SERVER-8944 Use C++11 standard library functions for double NaN and Infinity detection
Diffstat (limited to 'src/mongo/bson')
-rw-r--r--src/mongo/bson/bsonelement.cpp11
-rw-r--r--src/mongo/bson/bsonelement.h4
2 files changed, 7 insertions, 8 deletions
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp
index 0502038e668..7960209963b 100644
--- a/src/mongo/bson/bsonelement.cpp
+++ b/src/mongo/bson/bsonelement.cpp
@@ -31,6 +31,7 @@
#include "mongo/bson/bsonelement.h"
+#include <cmath>
#include <boost/functional/hash.hpp>
#include "mongo/base/compare_numbers.h"
@@ -49,8 +50,6 @@ namespace mongo {
using std::string;
string BSONElement::jsonString( JsonStringFormat format, bool includeFieldNames, int pretty ) const {
- int sign;
-
std::stringstream s;
if ( includeFieldNames )
s << '"' << escape( fieldName() ) << "\" : ";
@@ -81,11 +80,11 @@ namespace mongo {
// This is not valid JSON, but according to RFC-4627, "Numeric values that cannot be
// represented as sequences of digits (such as Infinity and NaN) are not permitted." so
// we are accepting the fact that if we have such values we cannot output valid JSON.
- else if ( mongo::isNaN(number()) ) {
+ else if ( std::isnan(number()) ) {
s << "NaN";
}
- else if ( mongo::isInf(number(), &sign) ) {
- s << ( sign == 1 ? "Infinity" : "-Infinity");
+ else if ( std::isinf(number()) ) {
+ s << ( number() > 0 ? "Infinity" : "-Infinity");
}
else {
StringBuilder ss;
@@ -973,7 +972,7 @@ namespace mongo {
// equal numbers and is still likely to be different for different numbers.
// SERVER-16851
const double dbl = elem.numberDouble();
- if (isNaN(dbl)) {
+ if (std::isnan(dbl)) {
boost::hash_combine(hash, std::numeric_limits<double>::quiet_NaN());
}
else {
diff --git a/src/mongo/bson/bsonelement.h b/src/mongo/bson/bsonelement.h
index a5937349399..386d2ac0020 100644
--- a/src/mongo/bson/bsonelement.h
+++ b/src/mongo/bson/bsonelement.h
@@ -29,6 +29,7 @@
#pragma once
+#include <cmath>
#include <string.h> // strlen
#include <string>
#include <vector>
@@ -38,7 +39,6 @@
#include "mongo/bson/oid.h"
#include "mongo/client/export_macros.h"
#include "mongo/platform/cstdint.h"
-#include "mongo/platform/float_utils.h"
namespace mongo {
class OpTime;
@@ -641,7 +641,7 @@ namespace mongo {
switch( type() ) {
case NumberDouble:
d = numberDouble();
- if ( isNaN( d ) ){
+ if ( std::isnan( d ) ){
return 0;
}
if ( d > (double) std::numeric_limits<long long>::max() ){