user1644002
user1644002

Reputation:

How do I use the Swift data type Float80 on an iPhone

I am using the current (January 2021) version of Xcode and an iPhone 12. I needed some extra precision in my floating point calculations for an astronomy function. Xcode and Swift supports the Float80 type and I updated the program using it. It works on the Xcode iPhone simulator. But when I try load the app to my iPhone 12, it won't, and the message says Float80 is "not available on the target".

Am I doing something wrong, or is my expectation incorrect? Is there another approach I can use to get standard 80 bit float?

Upvotes: 2

Views: 562

Answers (1)

dumbass
dumbass

Reputation: 27219

You don’t.

The 80-bit floating point format is natively supported only by one CPU architecture (though a popular one), namely x86. It is considered somewhat deprecated even there, as it is supported only in the legacy x87 instruction set (and not in the SSE instruction set preferred by modern software). The format is provided mostly for the sake of ABI compatibility with older software; Swift’s support for it depends on LLVM’s support, which in turn is only provided on x86. Other architectures would require a software implementation of 80-bit floating point, but the compiler does not provide one.

iPhones are based on the ARM architecture, which unlike x86 has never implemented 80-bit floating-point arithmetic in hardware. This format is available in the simulator only because programs running in the simulator are compiled for the architecture of the host running the simulator, which is based on x86 (though with Apple Silicon migration underway, that’s not going to be true for much longer).

If you need more floating-point precision than the 64-bit format can afford you, switch to a library implementation (which may provide arbitrary precision) or to the 128-bit format (which is usually implemented in software anyway). It seems Swift in particular does not currently support Float128, though adding such support is planned for the future.

Upvotes: 2

Related Questions