MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / div

Method div

src/common/Int128.cpp:208–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

206}
207
208Int128 Int128::div(Int128 op2, int scale) const
209{
210 if (compare(MIN_Int128) == 0 && op2.compare(minus1) == 0)
211 Arg::Gds(isc_exception_integer_overflow).raise();
212
213 if (op2.v == 0)
214 zerodivide();
215
216 static const CInt128 MIN_BY10(MIN_Int128 / 10);
217 static const CInt128 MAX_BY10(MAX_Int128 / 10);
218
219 // Scale op1 by as many of the needed powers of 10 as possible without an overflow.
220 Int128 op1(*this);
221 int sign1 = op1.sign();
222 while ((scale < 0) && (sign1 >= 0 ? op1.compare(MAX_BY10) <= 0 : op1.compare(MIN_BY10) >= 0))
223 {
224 op1.v *= 10;
225 ++scale;
226 }
227
228 // Scale op2 shifting it to the right as long as only zeroes are thrown away.
229 while (scale < 0)
230 {
231 int rem = int(v % 10);
232 if (rem)
233 break;
234 op2.v /= 10;
235 ++scale;
236 }
237
238 op1.v /= op2.v;
239
240 op1.setScale(scale);
241 return op1;
242}
243
244void Int128::zerodivide()
245{

Callers 7

divide2Method · 0.45
aggExecuteMethod · 0.45
evlCeilFunction · 0.45
evlFloorFunction · 0.45
evlLogFunction · 0.45
evlTruncFunction · 0.45
ticksToNanosecondsFunction · 0.45

Calls 8

GdsClass · 0.85
compareClass · 0.50
compareMethod · 0.45
raiseMethod · 0.45
signMethod · 0.45
setScaleMethod · 0.45
DivIntMethod · 0.45
DivMethod · 0.45

Tested by

no test coverage detected