apple / swift-numerics

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

Add new rounding modes: toNearestOr[Down,Up,Zero,Away] #296

Closed stephentyrone closed 1 month ago

stephentyrone commented 1 month ago

These were omitted in the first pass over integer rounding rules, but are generally useful and make good sense to have available. In particular, toNearestOrUp is the natural mode for a lot of fixed-point arithmetic, and frequently has HW support on SIMD units, so it makes good sense to have a name for that. Once you add that, having nearestOrDown also makes sense, and then nearestOrZero should exist by analogy to nearestOrAway. Also beefed up testing and refactored the division rounding code somewhat.

Also renamed toNearestOrAwayFromZero to toNearestOrAway for symmetry. The original name was never released, but we'll keep it around in deprecated form anyway.

stephentyrone commented 1 month ago

@swift-ci test

stephentyrone commented 1 month ago

@swift-ci test