You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To enable custom implementations of FixedWidthInteger, and to speed up and simplify generic code that needs to initialize integer types (especially those that are wider than UInt64) from arbitrary data, we should add dedicated initializers to BinaryInteger that take a specific word or a sequence of words in two's complement representation:
The single-word initializer is only there to provide a potential speed boost for the most common case. For FixedWidthInteger (and possibly also BinaryInteger itself), it seems possible to provide a default implementation for the sequence-based initializer using the single-word initializer and shifts, but it seems better to leave init(truncatingWordsIfNeeded: ) as a required initializer. (The default implementation would be quadratic for most big integer types.)
Note that for FixedWidthInteger, we currently require the underscored initializer FixedWidthInteger.init(_truncatingBits bits: UInt), without providing a default implementation. This makes it impossible to implement FixedWidthInteger using just the public API.
The text was updated successfully, but these errors were encountered:
A words-based initializer could also be useful for an improved version of the ExpressibleByIntegerLiteral protocol that would support integer literals of truly arbitrary widths.
@xwu: They behave the same, but the former is a specialization of a generic requirement that can be implemented with the latter. (My suggested names above aren't great; perhaps init(word: UInt) and init<S>(words: S) would work just as well.)
(FixedWidthInteger.init<T>(truncatingIfNeeded: T) is currently implemented using .init(_truncatingBits: ), which is the single-word initializer.)
Additional Detail from JIRA
md5: ee8ac7bc3cc99994b8ee663af146b48e
Issue Description:
To enable custom implementations of FixedWidthInteger, and to speed up and simplify generic code that needs to initialize integer types (especially those that are wider than UInt64) from arbitrary data, we should add dedicated initializers to BinaryInteger that take a specific word or a sequence of words in two's complement representation:
The new initializers should be public.
The single-word initializer is only there to provide a potential speed boost for the most common case. For FixedWidthInteger (and possibly also BinaryInteger itself), it seems possible to provide a default implementation for the sequence-based initializer using the single-word initializer and shifts, but it seems better to leave init(truncatingWordsIfNeeded: ) as a required initializer. (The default implementation would be quadratic for most big integer types.)
Note that for FixedWidthInteger, we currently require the underscored initializer FixedWidthInteger.init(_truncatingBits bits: UInt), without providing a default implementation. This makes it impossible to implement FixedWidthInteger using just the public API.
The text was updated successfully, but these errors were encountered: