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

Method Pow

extern/ttmath/ttmathuint.h:2362–2390  ·  view source on GitHub ↗

! power this = this ^ pow binary algorithm (r-to-l) return values: 0 - ok 1 - carry 2 - incorrect argument (0^0) */

Source from the content-addressed store, hash-verified

2360 2 - incorrect argument (0^0)
2361 */
2362 uint Pow(UInt<value_size> pow)
2363 {
2364 if(pow.IsZero() && IsZero())
2365 // we don't define zero^zero
2366 return 2;
2367
2368 UInt<value_size> start(*this);
2369 UInt<value_size> result;
2370 result.SetOne();
2371 uint c = 0;
2372
2373 while( !c )
2374 {
2375 if( pow.table[0] & 1 )
2376 c += result.Mul(start);
2377
2378 pow.Rcr2_one(0);
2379 if( pow.IsZero() )
2380 break;
2381
2382 c += start.Mul(start);
2383 }
2384
2385 *this = result;
2386
2387 TTMATH_LOGC("UInt::Pow(UInt<>)", c)
2388
2389 return (c==0)? 0 : 1;
2390 }
2391
2392
2393 /*!

Callers

nothing calls this directly

Calls 4

IsZeroMethod · 0.80
SetOneMethod · 0.80
MulMethod · 0.45
Rcr2_oneMethod · 0.45

Tested by

no test coverage detected