[swift-evolution] [Pitch] 'Double modulo' operator

Adam Nemecek adamnemecek at gmail.com
Sat May 21 20:23:05 CDT 2016


> If you pass an out-of-range argument, you should reject it using a
precondition

Different use case. I have a circular buffer.

> . And if for some reason you really *do* want to force the value into the
range, clamping it to the bounds of the range seems like a more sensible
solution than modulo

I have a circular buffer, I don't want to be clamping it to the bounds of
the range.

> I'm sure there are cases where you *would* want to do this, but they seem
like they'd be few and far between.

It's the 'correct' implementation of modulo.

On Sat, May 21, 2016 at 4:40 PM, Brent Royal-Gordon <brent at architechies.com>
wrote:

> > You are not taking into account when a function is passed an argument
> and needs it to be in some range.
>
> If you pass an out-of-range argument, you should reject it using a
> precondition, thrown error, or nil return value. And if for some reason you
> really *do* want to force the value into the range, clamping it to the
> bounds of the range seems like a more sensible solution than modulo. I'm
> sure there are cases where you *would* want to do this, but they seem like
> they'd be few and far between.
>
> --
> Brent Royal-Gordon
> Architechies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160521/c7adf3f1/attachment.html>


More information about the swift-evolution mailing list