Board index » delphi » I need Integer based Sqrt function, please.

I need Integer based Sqrt function, please.

Hi,
 I keep getting that runtime error you get when you try to get the sqrt of
some huge number. well i've had enough, i'm gonna be rounding the value
once i get it anyway, so i don't much care about it being exact, just
reasonably close. If anybody has such a procedure preferrably in Assembly
Language,( anything is good though) , that uses only integer arithmetic,
then PLEASE send it my way.  I'll even take an algorithm in English, and
develop the source myself if need be. Thank You VERY much ahead of time.
     Sincerely,
     Chris Johnson  
     Please E-Mail Response to:   Chris...@aol.com

 

Re:I need Integer based Sqrt function, please.


Quote
Chris R Us wrote:

> Hi,
>  I keep getting that runtime error you get when you try to get the sqrt of
> some huge number. well i've had enough, i'm gonna be rounding the value
> once i get it anyway, so i don't much care about it being exact, just
> reasonably close. If anybody has such a procedure preferrably in Assembly
> Language,( anything is good though) , that uses only integer arithmetic,
> then PLEASE send it my way.  I'll even take an algorithm in English, and
> develop the source myself if need be. Thank You VERY much ahead of time.
>      Sincerely,
>      Chris Johnson
>      Please E-Mail Response to:   Chris...@aol.com

From my copy of the Borland C++ Handbook, 4th ed.:

"What follows is an interesting mathematical approach for extracting a square
root of a hexadecimal number.  The algorithm is as follows:  You can approximate
the square root of a number by subtracting successively higher odd numbers from
the original number until that original number is reduced to zero.  The number of
subtractions is equal to the approximate square root of the original number.  For
example, to find the square root of 110 decimal:

  110 -  1 = 109
  109 -  3 = 106
  106 -  5 = 101
  101 -  7 =  94
  94  -  9 =  85
  85  - 11 =  74
  74  - 13 =  61
  61  - 15 =  46
  46  - 17 =  29
  29  - 19 =  10 <- subtraction #10
  10  - 21 = -11

"Thus, the approximate square root of 110 is 10.  The same mathematical procedure
works in hexadecimal.  [. . .]"

I haven't actually implemented this in TP, but with this description, it should
be easy to figure out with a simple iterative function.

Quote
>      Sincerely,
>      Chris Johnson
>      Please E-Mail Response to:   Chris...@aol.com

--
Scott Earnest                      | _,-""-_,-""-_,-""-_,-""-_,-""-_,-" |
set...@ix.netcom.com (primary)     | We now return you to our regularly |
siny...@{*word*104}space.org (alternate) | scheduled chaos and mayhem. . . .  |

Other Threads