summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bsonelement.h
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2022-08-02 13:48:25 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-02 15:29:23 +0000
commited25ebe0d87dd2521fbfc5534ba7af7de69aad4d (patch)
tree7a4904289fc5ffcf183f302434a0cea16b7151ae /src/mongo/bson/bsonelement.h
parentfc5d35bb08d81f0cd165296760c4ab7506fcff1c (diff)
downloadmongo-ed25ebe0d87dd2521fbfc5534ba7af7de69aad4d.tar.gz
SERVER-68487 add BSONElement::isNaN()
Diffstat (limited to 'src/mongo/bson/bsonelement.h')
-rw-r--r--src/mongo/bson/bsonelement.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/mongo/bson/bsonelement.h b/src/mongo/bson/bsonelement.h
index e0b3b8e4414..1d31c647901 100644
--- a/src/mongo/bson/bsonelement.h
+++ b/src/mongo/bson/bsonelement.h
@@ -373,6 +373,11 @@ public:
bool isNumber() const;
/**
+ * True if element is a NaN double or decimal.
+ */
+ bool isNaN() const;
+
+ /**
* Return double value for this field. MUST be NumberDouble type.
*/
double _numberDouble() const {
@@ -1005,6 +1010,21 @@ inline bool BSONElement::isNumber() const {
}
}
+inline bool BSONElement::isNaN() const {
+ switch (type()) {
+ case NumberDouble: {
+ double d = _numberDouble();
+ return std::isnan(d);
+ }
+ case NumberDecimal: {
+ Decimal128 d = _numberDecimal();
+ return d.isNaN();
+ }
+ default:
+ return false;
+ }
+}
+
inline Decimal128 BSONElement::numberDecimal() const {
switch (type()) {
case NumberDouble: