MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / castValue

Function castValue

lib/vf_common.cpp:343–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

341 }
342
343 Value castValue(Value value, const ValueType::Sign sign, nonneg int bit)
344 {
345 if (value.isFloatValue()) {
346 value.valueType = Value::ValueType::INT;
347 if (value.floatValue >= std::numeric_limits<int>::min() && value.floatValue <= std::numeric_limits<int>::max()) {
348 value.intvalue = static_cast<MathLib::bigint>(value.floatValue);
349 } else { // don't perform UB
350 value.intvalue = 0;
351 }
352 }
353 if (bit < MathLib::bigint_bits) {
354 constexpr MathLib::biguint one = 1;
355 value.intvalue &= (one << bit) - 1;
356 if (sign == ValueType::Sign::SIGNED && value.intvalue & (one << (bit - 1))) {
357 value.intvalue |= ~((one << bit) - 1ULL);
358 }
359 }
360 return value;
361 }
362
363 std::string debugString(const Value& v)
364 {

Callers 2

setTokenValueCastFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected