MCPcopy Create free account
hub / github.com/Tencent/TAD_Sim / checked_multiply

Function checked_multiply

simcore/framework/src/cli/cli.hpp:2690–2703  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2688/// Performs a *= b; if it doesn't cause integer overflow. Returns false otherwise.
2689template <typename T>
2690typename std::enable_if<std::is_integral<T>::value, bool>::type checked_multiply(T &a, T b) {
2691 if (a == 0 || b == 0 || a == 1 || b == 1) {
2692 a *= b;
2693 return true;
2694 }
2695 if (a == (std::numeric_limits<T>::min)() || b == (std::numeric_limits<T>::min)()) {
2696 return false;
2697 }
2698 if (overflowCheck(a, b)) {
2699 return false;
2700 }
2701 a *= b;
2702 return true;
2703}
2704
2705/// Performs a *= b; if it doesn't equal infinity. Returns false otherwise.
2706template <typename T>

Callers 2

AsNumberWithUnitMethod · 0.85

Calls 2

overflowCheckFunction · 0.85
isinfFunction · 0.85

Tested by

no test coverage detected