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

Method divide

lib/mathlib.cpp:1149–1170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1147}
1148
1149std::string MathLib::divide(const std::string &first, const std::string &second)
1150{
1151#ifdef TEST_MATHLIB_VALUE
1152 return (value(first) / value(second)).str();
1153#else
1154 if (MathLib::isInt(first) && MathLib::isInt(second)) {
1155 const bigint a = toBigNumber(first);
1156 const bigint b = toBigNumber(second);
1157 if (b == 0)
1158 throw InternalError(nullptr, "Internal Error: Division by zero");
1159 if (a == std::numeric_limits<bigint>::min() && std::abs(b)<=1)
1160 throw InternalError(nullptr, "Internal Error: Division overflow");
1161 return MathLib::toString(toBigNumber(first) / b) + intsuffix(first, second);
1162 }
1163 if (isNullValue(second)) {
1164 if (isNullValue(first))
1165 return "nan.0";
1166 return isPositive(first) == isPositive(second) ? "inf.0" : "-inf.0";
1167 }
1168 return toString(toDoubleNumber(first) / toDoubleNumber(second));
1169#endif
1170}
1171
1172std::string MathLib::multiply(const std::string &first, const std::string &second)
1173{

Callers

nothing calls this directly

Calls 4

intsuffixFunction · 0.85
valueClass · 0.70
toStringFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected