| 1147 | } |
| 1148 | |
| 1149 | std::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 | |
| 1172 | std::string MathLib::multiply(const std::string &first, const std::string &second) |
| 1173 | { |