Integer square root
Kenji Rikitake
kenji.rikitake@REDACTED
Tue Jan 26 02:26:47 CET 2010
Very long time ago I was trying to solve the square root
problem, but I didn't because handling in the float numbers
gave the sufficient precision for me.
In general, a quick method of
solving X when Y = X * X and Y is given (X, Y are bignums) as:
1) Obtain approximation of X by float sqrt of Y
separately to significand and exponent
(note: IEEE754 format has its own limits in
the digits of exponent too)
2) applying Newton-Raphson method so that
Xnew = (X + (Y / X)) / 2
3) Repeat finding Xnew on 2) until Xnew =:= X
Things you need to invent:
* bignum integer dividing program
(bignum / bignum -> bignum (+ remainder, maybe))
(This is NOT provided by Erlang)
FYI
Kenji Rikitake
In the message <73BF5BD8-2DBB-44E3-BD45-C658B4059206@REDACTED>
dated Mon, Jan 25, 2010 at 07:33:03PM +1300,
Richard O'Keefe <ok@REDACTED> writes:
> Didn't we have exactly this conversation several months ago?
> At the time I said that it is straightforward to write an
> integer square root function, and by that I meant >> in Erlang <<,
> no port programs needed.
More information about the erlang-questions
mailing list