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

Method Div3_Calculate

extern/ttmath/ttmathuint.h:2266–2315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2264
2265
2266 uint Div3_Calculate(uint u2, uint u1, uint u0, uint v1, uint v0)
2267 {
2268 UInt<2> u_temp;
2269 uint rp;
2270 bool next_test;
2271
2272 TTMATH_ASSERT( v1 != 0 )
2273
2274 u_temp.table[1] = u2;
2275 u_temp.table[0] = u1;
2276 u_temp.DivInt(v1, &rp);
2277
2278 TTMATH_ASSERT( u_temp.table[1]==0 || u_temp.table[1]==1 )
2279
2280 do
2281 {
2282 bool decrease = false;
2283
2284 if( u_temp.table[1] == 1 )
2285 decrease = true;
2286 else
2287 {
2288 UInt<2> temp1, temp2;
2289
2290 UInt<2>::MulTwoWords(u_temp.table[0], v0, temp1.table+1, temp1.table);
2291 temp2.table[1] = rp;
2292 temp2.table[0] = u0;
2293
2294 if( temp1 > temp2 )
2295 decrease = true;
2296 }
2297
2298 next_test = false;
2299
2300 if( decrease )
2301 {
2302 u_temp.SubOne();
2303
2304 rp += v1;
2305
2306 if( rp >= v1 ) // it means that there wasn't a carry (r<b from the book)
2307 next_test = true;
2308 }
2309 }
2310 while( next_test );
2311
2312 TTMATH_LOG("UInt::Div3_Calculate")
2313
2314 return u_temp.table[0];
2315 }
2316
2317
2318

Callers

nothing calls this directly

Calls 2

DivIntMethod · 0.45
SubOneMethod · 0.45

Tested by

no test coverage detected