I was looking at another question (here) where someone was looking for a way to get the square root of a 64 bit integer in x86 assembly.
This turns out to be very simple. The solution is to convert to a floating point number, calculate the sqrt and then convert back.
I need to do something very similar in C however when I look into equivalents I'm getting a little stuck. I can only find a sqrt function which takes in doubles. Doubles do not have the precision to store large 64bit integers without introducing significant rounding error.
Is there a common math library that I can use which has a long double
sqrt function?
Function
sqrtl()
, taking along double
, is part of C99.Note that your compilation platform does not have to implement
long double
as 80-bit extended-precision. It is only required to be as wide asdouble
, and Visual Studio implements is as a plaindouble
. GCC and Clang do compilelong double
to 80-bit extended-precision on Intel processors.