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

Function AddDoubleToValue

pg_documentdb_core/src/io/pgbson_utils.c:870–895  ·  view source on GitHub ↗

* Adds a double to the current value. * */

Source from the content-addressed store, hash-verified

868 *
869 */
870static void
871AddDoubleToValue(bson_value_t *current, double value)
872{
873 /* If existing value is decimal128, then needs to convert the value to decimal128 */
874 if (current->value_type == BSON_TYPE_DECIMAL128)
875 {
876 bson_value_t valueBson;
877 valueBson.value.v_double = value;
878 valueBson.value_type = BSON_TYPE_DOUBLE;
879
880 /* Transform value into decimal128 format */
881 valueBson.value.v_decimal128 = GetBsonValueAsDecimal128Quantized(&valueBson);
882 valueBson.value_type = BSON_TYPE_DECIMAL128;
883
884 AddDecimal128Numbers(current, &valueBson, current);
885 }
886 else
887 {
888 /* We match protocol behavior, which doesn't coerce to decimal128
889 * in case of overflow and just returns infinity which is the same
890 * behavior in C in case of double overflow. */
891 double currentValue = BsonValueAsDouble(current);
892 current->value_type = BSON_TYPE_DOUBLE;
893 current->value.v_double = currentValue + value;
894 }
895}
896
897
898/**

Callers 4

AddNumberToBsonValueFunction · 0.85
AddInt32ToValueFunction · 0.85
AddInt64ToValueFunction · 0.85

Calls 3

AddDecimal128NumbersFunction · 0.85
BsonValueAsDoubleFunction · 0.85

Tested by

no test coverage detected