| 123 | |
| 124 | |
| 125 | MathLib::value MathLib::value::calc(char op, const MathLib::value &v1, const MathLib::value &v2) |
| 126 | { |
| 127 | value temp(v1); |
| 128 | temp.promote(v2); |
| 129 | if (temp.isFloat()) { |
| 130 | switch (op) { |
| 131 | case '+': |
| 132 | temp.mDoubleValue += v2.getDoubleValue(); |
| 133 | break; |
| 134 | case '-': |
| 135 | temp.mDoubleValue -= v2.getDoubleValue(); |
| 136 | break; |
| 137 | case '*': |
| 138 | temp.mDoubleValue *= v2.getDoubleValue(); |
| 139 | break; |
| 140 | case '/': |
| 141 | temp.mDoubleValue /= v2.getDoubleValue(); |
| 142 | break; |
| 143 | case '%': |
| 144 | case '&': |
| 145 | case '|': |
| 146 | case '^': |
| 147 | throw InternalError(nullptr, "Invalid calculation"); |
| 148 | default: |
| 149 | throw InternalError(nullptr, "Unhandled calculation"); |
| 150 | } |
| 151 | } else if (temp.mIsUnsigned) { |
| 152 | switch (op) { |
| 153 | case '+': |
| 154 | temp.mIntValue += static_cast<unsigned long long>(v2.mIntValue); |
| 155 | break; |
| 156 | case '-': |
| 157 | temp.mIntValue -= static_cast<unsigned long long>(v2.mIntValue); |
| 158 | break; |
| 159 | case '*': |
| 160 | temp.mIntValue *= static_cast<unsigned long long>(v2.mIntValue); |
| 161 | break; |
| 162 | case '/': |
| 163 | if (v2.mIntValue == 0) |
| 164 | throw InternalError(nullptr, "Internal Error: Division by zero"); |
| 165 | if (v1.mIntValue == std::numeric_limits<bigint>::min() && std::abs(v2.mIntValue)<=1) |
| 166 | throw InternalError(nullptr, "Internal Error: Division overflow"); |
| 167 | temp.mIntValue /= static_cast<unsigned long long>(v2.mIntValue); |
| 168 | break; |
| 169 | case '%': |
| 170 | if (v2.mIntValue == 0) |
| 171 | throw InternalError(nullptr, "Internal Error: Division by zero"); |
| 172 | temp.mIntValue %= static_cast<unsigned long long>(v2.mIntValue); |
| 173 | break; |
| 174 | case '&': |
| 175 | temp.mIntValue &= static_cast<unsigned long long>(v2.mIntValue); |
| 176 | break; |
| 177 | case '|': |
| 178 | temp.mIntValue |= static_cast<unsigned long long>(v2.mIntValue); |
| 179 | break; |
| 180 | case '^': |
| 181 | temp.mIntValue ^= static_cast<unsigned long long>(v2.mIntValue); |
| 182 | break; |
nothing calls this directly
no test coverage detected