User:Hogü-456/Integer square root implementation
Appearance
There is the function integer square root (Z15256) what is a function that returns the integer of a square root. At this page you can find a implementation I want to implement.
Implementation using difference method
Background
The distance between two sqare numbers increases by two. The first distance is 3 between 1 and 2 if you multiply these numbers with themselve.
Algorithm
Here you can find a explanation based on a example. Given the number 54 the algorith is as described below.
- Check if the number is greater than or equal one.
- If this is true then initialize the result variable with a one.
- If this is true then initialize the variable for the distance counter with 3.
- Initialize Nextresultvariable with one
- If this is true then set Nextresultvariable up by the value of distance counter.
- Check if the Inputvalue is lower than the value of Nextresultvariable.
- If this is true then the result is the value of result variable.
- Check if the Inputvalue is equal the value of Nextresultvariable.
- Set value of result variable up by one and you have the result.