What's the difference between CLongDouble and Double?
According to Apple document, CLongDouble is an alias of Double. However, when I run the following code, I get different max number results.
print(Double.greatestFiniteMagnitude) // 1.7976931348623157e+308
print(CLongDouble.greatestFiniteMagnitude). // 1.189731495357231765e+4932
Are there really the same type? Also, which type is more precise?
That could be a documentation problem.
CLongDouble is defined in CTypes.swift as
Double or as
Float80, depending on the platform.
In a macOS command line project I get this:
print(CLongDouble.self) // Float80
print(MemoryLayout<CLongDouble>.size) // 16
Thank you very much. Hope the document will be fixed soon
CLongDouble should be whatever type
long double is in clang on the target platform. In particular, when targeting x86_64 on Linux or macOS, it is
Float80, but when targeting
arm64 on macOS, it is
Double. The documentation site that you linked to doesn't handle per-arch differences in definitions or availability (see also CFloat16, which doesn't exist on macOS/x86_64), but this is documented (somewhat tersely) in the source.
Just for the record, I filed a documentation bug about this (r. 92595826).
Share and Enjoy
Quinn “The Eskimo!” @ DTS @ Apple