integer square root function without using floating point */
| 679 | |
| 680 | /* integer square root function without using floating point */ |
| 681 | int |
| 682 | isqrt(int val) |
| 683 | { |
| 684 | int rt = 0; |
| 685 | int odd = 1; |
| 686 | /* |
| 687 | * This could be replaced by a faster algorithm, but has not been because: |
| 688 | * + the simple algorithm is easy to read; |
| 689 | * + this algorithm does not require 64-bit support; |
| 690 | * + in current usage, the values passed to isqrt() are not really that |
| 691 | * large, so the performance difference is negligible; |
| 692 | * + isqrt() is used in only few places, which are not bottle-necks. |
| 693 | */ |
| 694 | while (val >= odd) { |
| 695 | val = val - odd; |
| 696 | odd = odd + 2; |
| 697 | rt = rt + 1; |
| 698 | } |
| 699 | return rt; |
| 700 | } |
| 701 | |
| 702 | /* are two points lined up (on a straight line)? */ |
| 703 | boolean |
no outgoing calls
no test coverage detected