MCPcopy Create free account
hub / github.com/bytedance/bolt / toFloatFromValue

Method toFloatFromValue

bolt/type/FloatingDecimal.cpp:388–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

386}
387
388std::optional<float> FloatingDecimal::toFloatFromValue(
389 int128_t value,
390 int32_t scale) {
391 float sign = 1;
392 if (value < 0) {
393 value = -value;
394 sign = -1;
395 }
396 int32_t nDigits = 0;
397 std::string valueStr = valueToString(value, scale, nDigits);
398 int32_t decExponent = nDigits - scale;
399 auto res = floatValue(valueStr, nDigits, decExponent);
400 if (res.has_value()) {
401 return *res * sign;
402 }
403 return {};
404}
405
406std::optional<float> FloatingDecimal::floatValue(
407 std::string& value,

Callers

nothing calls this directly

Calls 2

valueToStringFunction · 0.85
has_valueMethod · 0.80

Tested by

no test coverage detected