Are swift binary integers guaranteed to be 2's compliment

I don’t see this mentioned anywhere in the language, but some of function descriptions do make it sound like it. For example the descriptions of min and max.

An implementation can technically use whatever representation it wants and conform to FixedWidthInteger, but the conformance requires it to behave like a twos-complement integer regardless of how it is actually implemented under the covers.

(i.e. an implementor can certainly implement Int512 backed by a signed-magnitude representation, but it would have the same range and arithmetic as a twos-complement representation. E.g. ~x = 0 &- x &- 1)

7 Likes

Yeah, that’s what it seemed like, but wasn’t explicitly called out except for a few function descriptions. Thanks!