Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

More precision than double in swift

Are there are any floating points more accurate than Double available in Swift? I know that in C there is the long double, but I can't seem to find its equivalent in Apple's new programming language.

Any help would be greatly appreciated!

like image 992
Giulio Crisanti Avatar asked Oct 08 '15 18:10

Giulio Crisanti


2 Answers

Yes there is! There is Float80 exactly for that, it stores 80 bits (duh), 10 bytes. You can use it like any other floating point type. Note that there are Float32, Float64 and Float80 in Swift, where Float32 is just a typealias for Float and Float64 is one for Double

like image 193
Kametrixom Avatar answered Sep 29 '22 16:09

Kametrixom


Currently iOS 11+ runs on 64 Bit platform, Double holds Highest among all.

Double has a precision of at least 15 decimal digits, whereas the precision of Float can be as little as 6 decimal digits. The appropriate floating-point type to use depends on the nature and range of values you need to work with in your code. In situations where either type would be appropriate, Double is preferred.

However in CGFloat The native type used to store the CGFloat, which is Float on 32-bit architectures and Double on 64-bit architectures

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html

like image 44
Jack Avatar answered Sep 29 '22 15:09

Jack