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

Method subtract

lib/mathlib.cpp:1124–1147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1122}
1123
1124std::string MathLib::subtract(const std::string &first, const std::string &second)
1125{
1126#ifdef TEST_MATHLIB_VALUE
1127 return (value(first) - value(second)).str();
1128#else
1129 if (MathLib::isInt(first) && MathLib::isInt(second)) {
1130 return MathLib::toString(toBigNumber(first) - toBigNumber(second)) + intsuffix(first, second);
1131 }
1132
1133 if (first == second)
1134 return "0.0";
1135
1136 double d1 = toDoubleNumber(first);
1137 double d2 = toDoubleNumber(second);
1138
1139 int count = 0;
1140 while (d1 > 100000.0 * d2 && toString(d1-d2)==first && ++count<5)
1141 d2 *= 10.0;
1142 while (d2 > 100000.0 * d1 && toString(d1-d2)==second && ++count<5)
1143 d1 *= 10.0;
1144
1145 return toString(d1 - d2);
1146#endif
1147}
1148
1149std::string MathLib::divide(const std::string &first, const std::string &second)
1150{

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