sqrt of uint64_t vs. int64_t
问题 I noticed that calculating the integer part of square root of uint64_t is much more complicated than of int64_t . Please, does anybody have an explanation for this? Why is it seemingly much more difficult to deal with one extra bit? The following: int64_t sqrt_int(int64_t a) { return sqrt(a); } compiles with clang 5.0 and -mfpmath=sse -msse3 -Wall -O3 to sqrt_int(long): # @sqrt_int(long) cvtsi2sd xmm0, rdi sqrtsd xmm0, xmm0 cvttsd2si rax, xmm0 ret But the following: uint64_t sqrt_int(uint64_t