#How to calculate sqrt(float)

23 messages · Page 1 of 1 (latest)

white bobcat
#

Is there some good algorithm to calculate the sqrt of a float or double? (In CS)

junior kayak
#

Like calculating sqrt 0.02?

#

@white bobcat

white bobcat
#

Yes

#

Or maybe sqrt(19287.39)

#

The input will be random

stable tide
#

how precise do you want it to be?

#

i derived one funny algorithm but its mostly just for a pen & paper calculation

#

just so that you can approximate the number

#

for anything actually precise you probably want more advanced existing methods

#

and maybe a couple of newton's method to improve the result

stable tide
#

(yes, im still proud of my approximation)

#

let me write it on python to show how it

#

and it can also be written somewhat fast because float bit manipulation

#

it gets worse tho for larger and larger numbers

#

you might think 0.03 away isnt that bad

#

but it is

stable tide
#

but whats also fun is that it can be expanded to nth root

#

not just sqrt

white bobcat
stable tide
#

wow okay no this little funny algorithm is shit then lmao

#

uh