! square root e.g. Sqrt(9) = 3 ('digit-by-digit' algorithm) */
| 2396 | ('digit-by-digit' algorithm) |
| 2397 | */ |
| 2398 | void Sqrt() |
| 2399 | { |
| 2400 | UInt<value_size> bit, temp; |
| 2401 | |
| 2402 | if( IsZero() ) |
| 2403 | return; |
| 2404 | |
| 2405 | UInt<value_size> value(*this); |
| 2406 | |
| 2407 | SetZero(); |
| 2408 | bit.SetZero(); |
| 2409 | bit.table[value_size-1] = (TTMATH_UINT_HIGHEST_BIT >> 1); |
| 2410 | |
| 2411 | while( bit > value ) |
| 2412 | bit.Rcr(2); |
| 2413 | |
| 2414 | while( !bit.IsZero() ) |
| 2415 | { |
| 2416 | temp = *this; |
| 2417 | temp.Add(bit); |
| 2418 | |
| 2419 | if( value >= temp ) |
| 2420 | { |
| 2421 | value.Sub(temp); |
| 2422 | Rcr(1); |
| 2423 | Add(bit); |
| 2424 | } |
| 2425 | else |
| 2426 | { |
| 2427 | Rcr(1); |
| 2428 | } |
| 2429 | |
| 2430 | bit.Rcr(2); |
| 2431 | } |
| 2432 | |
| 2433 | TTMATH_LOG("UInt::Sqrt") |
| 2434 | } |
| 2435 | |
| 2436 | |
| 2437 |