You are correct, it is off-topic. It was just a (too much detailed) warning.
I donât think this API is motivated by a desire to actually store attoseconds. The desire is to store higher-resolution durations than can be stored in an Int64, and Int128 is the next size up that computers generally make available. It might seem âwastefulâ in that most real-world instances of this type the several least significant bits will be zero, but alternatives like (Int64, UInt8)
are more cumbersome to work with and possibly even less efficient at runtime.
Yes, that sounds reasonable to me.
On the more general issue of Int128
support in Swift, it's perhaps worth reiterating in this 128-bit-focused thread that 1_000_000_000_000_000_000_000_000_000_000_000_000
is a preposterous thing to see in code, even if it were to yield a BinaryInteger
of appropriate width.
In theory the underbars are there in contemplation of the fact that someone might need to count up the zeros by hand. But I'm not sure I could even write this correctly without underbars.
As is no doubt clear to everyone already, this number should be spelled 1E36
. I've found myself regretting the lack of exponential notation for integer constants on multiple occasions.
Just out of curiosity, why is var attoseconds: Int128
read-only?
We'll have to access directly var _low: UInt64
and var _high: Int64
to mutate an instance even if this proposal is realized.
Interesting. I canât think of a reason why not to do this but also no reasons why we should do it.
Do you have specific use cases in mind where this is helpful? I guess it is slightly shorter:
duration.attoseconds + 1
vs
duration + Duration(attoseconds: 1)
But on the other hand it looks odd having one addend without scale, no?
Curious what others think about this.
duration.attoseconds += 1
came to my mind, but, to be honest, the reason why I wondered about setter missing was just because _low
and _high
were writable.
This is one of the few proposals I've read recently that seems unambiguously sensible. +1.
Hi all, this proposal has been accepted. Thanks for your attention!