| 1122 | } |
| 1123 | |
| 1124 | std::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 | |
| 1149 | std::string MathLib::divide(const std::string &first, const std::string &second) |
| 1150 | { |