Add a type like Double but with much more precision?


#1

I need a floating-point type with more precision than Double. Would this be
possible to add in Swift?
Here is just one use case: Measuring time using seconds since the first
instant of 1970. For example, the first instant of 2016 is 1451602800.0
seconds since the first instance of 1970. But with 1451602800.0, I'm already
at 11 significant digits. This means I cannot add a nanosecond (1e-9) to this
number within Double's precision because that would require a lot more
significant digits than Double can handle.


(Brent Royal-Gordon) #2

I need a floating-point type with more precision than Double.

There’s a Float80, at least on OS X. (Not sure about iOS or Linux.) Does that meet your needs?

···

--
Brent Royal-Gordon
Architechies


(Joe Groff) #3

Should be available on x86_64 or i386 Linux as well.

-Joe

···

On Dec 8, 2015, at 2:01 PM, Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org> wrote:

I need a floating-point type with more precision than Double.

There’s a Float80, at least on OS X. (Not sure about iOS or Linux.) Does that meet your needs?


(Joe Groff) #4

There's support at the LLVM level for fp128 types. I'm not sure how good or portable its backend support is though. You might look at FloatingPoint.swift.gyb and see what breaks if you extend it to generate a Quad type backed by Builtin.FPIEEE128.

-Joe

···

On Dec 8, 2015, at 10:27 AM, Tuur Anton via swift-evolution <swift-evolution@swift.org> wrote:

I need a floating-point type with more precision than Double. Would this be possible to add in Swift?

Here is just one use case: Measuring time using seconds since the first instant of 1970. For example, the first instant of 2016 is 1451602800.0 seconds since the first instance of 1970. But with 1451602800.0, I'm already at 11 significant digits. This means I cannot add a nanosecond (1e-9) to this number within Double's precision because that would require a lot more significant digits than Double can handle.