The documentation for sqrt
is available by running man sqrt
. Most Darwin functions are C functions bridged to Swift, and they're not documented inside of Xcode.
But you're asking for the implementation, which is a completely different thing than the documentation. To provide you with the implementation, you'd have to have all the source code, and things like stdlib, Foundation, and Darwin don't provide that directly because they're pre-compiled. Some of them are open source so you can in principle find the source code, but it's still very difficult to know that this is precisely the code you're using. This is pretty typical of compiled languages since there's no easy way to decompile them.
That said, most of the source code, as Ben notes, is available in various places if you know where to look. sqrt(Double)
is a good example of when this fails, though, because there is no implementation in the way you're likely thinking. It's inlined directly by the compiler via __builtin_sqrt
. On an Intel processor, that may be directly converted to the fsqrt
operation, it may be vectorized, it might be evaluated at compile time, or it might be inlined in various other ways. On different platforms, there are different options.
In your example, it's computed at compile time and encoded as though you'd written var result = 3.0
. You can see this in the LLVM IR output:
echo "import Darwin; var result = sqrt(9.0)" | swiftc -emit-ir -O -
...
define i32 @main(i32, i8** nocapture readnone) local_unnamed_addr #0 {
entry:
store double 3.000000e+00, double* getelementptr inbounds (%TSd, %TSd* @"$S4main6resultSdvp", i64 0, i32 0), align 8
ret i32 0
}
...
So there isn't any "implementation" that you could pull up. There is no real sqrt
function (though at least some versions of macOS have a fake one).
That said, I agree that it's really annoying that the relevant man pages aren't imported into Xcode somehow. It's probably a lot of work to do that because the docs for those functions are written in troff, which is probably a pain to convert to the doc format Xcode uses, but even so it'd be nice.