MCPcopy Create free account
hub / github.com/documentdb/documentdb / BsonValueAsDoubleCore

Function BsonValueAsDoubleCore

pg_documentdb_core/src/query/bson_compare.c:1503–1550  ·  view source on GitHub ↗

* Core implementation of converting bson value to double * In quiet mode no error is thrown if conversion results in overflow or underflow */

Source from the content-addressed store, hash-verified

1501 * In quiet mode no error is thrown if conversion results in overflow or underflow
1502 */
1503static double
1504BsonValueAsDoubleCore(const bson_value_t *value, bool quiet)
1505{
1506 switch (value->value_type)
1507 {
1508 case BSON_TYPE_BOOL:
1509 {
1510 return (double) value->value.v_bool;
1511 }
1512
1513 case BSON_TYPE_DOUBLE:
1514 {
1515 return value->value.v_double;
1516 }
1517
1518 case BSON_TYPE_INT32:
1519 {
1520 return (double) value->value.v_int32;
1521 }
1522
1523 case BSON_TYPE_INT64:
1524 {
1525 return (double) value->value.v_int64;
1526 }
1527
1528 case BSON_TYPE_DECIMAL128:
1529 {
1530 if (quiet)
1531 {
1532 return GetBsonDecimal128AsDoubleQuiet(value);
1533 }
1534 else
1535 {
1536 return GetBsonDecimal128AsDouble(value);
1537 }
1538 }
1539
1540 case BSON_TYPE_DATE_TIME:
1541 {
1542 return (double) value->value.v_datetime;
1543 }
1544
1545 default:
1546 {
1547 return 0;
1548 }
1549 }
1550}
1551
1552
1553/* Indicates whether the value can be represented as an int64 value without overflow or truncating decimal digits.

Callers 2

BsonValueAsDoubleFunction · 0.85
BsonValueAsDoubleQuietFunction · 0.85

Calls 2

Tested by

no test coverage detected