Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quotientAndRemainderReportingOverflow(dividingBy:) #88

Closed
oscbyspro opened this issue Apr 21, 2023 · 3 comments
Closed

quotientAndRemainderReportingOverflow(dividingBy:) #88

oscbyspro opened this issue Apr 21, 2023 · 3 comments
Labels
addition oh, so shiny!
Milestone

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Apr 21, 2023

Requested by (#84) and (#87). The former for performance and the latter for testability.

protocol ANKBinaryInteger {
    ....
    func quotientAndRemainderReportingOverflow(dividingBy divisor: Self) -> PVO<QR<Self, Self>>
}
protocol ANKLargeBinaryInteger {
    ....
    func quotientAndRemainderReportingOverflow(dividingBy divisor: Digit) -> PVO<QR<Self, Digit>>
}
@oscbyspro
Copy link
Owner Author

oscbyspro commented Apr 22, 2023

Note: I've had some success playing with the idea of "throwing overflow" vs "reporting overflow", but that's not really a design direction I can entertain without decoupling from the standard library. It might be a fun side project, however.

There's a lot of cool stuff you can do with this, especially considering that non-throwing methods can satisfy throwing method requirements. With throws you would only need one division method because you can simply try! to trap.

, hire me. I'm idea rich, but resource poor (。•́︿•̀。)

@oscbyspro
Copy link
Owner Author

oscbyspro commented Apr 22, 2023

Also, I wish the remainder part defaulted to the divisor rather than the dividend. It would be symmetric, in a way, because then I would not have to create some unrelated value in my digit methods (every valid remainder has a smaller magnitude than the divisor). Alternatively, if "reporting overflow" were "throwing" you wouldn't need to produce a junk value.

Edit: I suppose defaulting to the dividend makes sense when you consider mutating methods.

@oscbyspro
Copy link
Owner Author

oscbyspro commented Apr 22, 2023

7bcd36f Gotta add this method to ANKSigned too 🥱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition oh, so shiny!
Projects
None yet
Development

No branches or pull requests

1 participant