apple / swift-numerics

Advanced mathematical types and functions for Swift
Apache License 2.0
1.67k stars 142 forks source link

Right shift and division with rounding. #203

Closed stephentyrone closed 2 years ago

stephentyrone commented 2 years ago

Fairly correct implementation of right-shift and division with rounding. Also fairly efficient, though I'm sure I'll find some cases where we're generating uncessary overflow checks upon further inspection. Nonetheless, a decent enough start.

The methods are added to BinaryInteger:

The following methods are added to SignedInteger (not BinaryInteger, because the remainder is not generally representable in an UnsignedType when the rounding mode is not .down or .towardZero):

The following free function is added:

stephentyrone commented 2 years ago

@swift-ci test

stephentyrone commented 2 years ago

@swift-ci test

stephentyrone commented 2 years ago

@swift-ci test

stephentyrone commented 2 years ago

@swift-ci test

stephentyrone commented 2 years ago

@swift-ci test

stephentyrone commented 2 years ago

@swift-ci test

stephentyrone commented 2 years ago

@swift-ci test linux