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

Req. init?(magnitude:) #107

Closed
oscbyspro opened this issue Oct 31, 2023 · 2 comments
Closed

Req. init?(magnitude:) #107

oscbyspro opened this issue Oct 31, 2023 · 2 comments
Labels
addition oh, so shiny!
Milestone

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Oct 31, 2023

The init?(sign:magnitude:) method is rather useful, but it feels silly to use when the sign is known to be positive at compile time — because what's sign-magnitude without the sign? The compiler can probably fold it into init(magnitude:) when it is marked as @inlinable, but perhaps being explicit about it is preferred?

@oscbyspro oscbyspro added addition oh, so shiny! maybe to do, or not to do? labels Oct 31, 2023
@oscbyspro oscbyspro changed the title Req. init(magnitude:) Req. init?(magnitude:) Nov 1, 2023
@oscbyspro
Copy link
Owner Author

Is this method necessary? I don't know? But it makes a lot of sense to me, and a lot more now that I'm going beyond fixed-width stuff where generic algorithms can do whatever via init(bitPattern:). It's similar to init(digit:). If there's a named type relationship, then the relationship is probably important enough that it deserves a named initializer. That's my current thoughts on it, at least.

@oscbyspro oscbyspro removed the maybe to do, or not to do? label Nov 1, 2023
@oscbyspro oscbyspro added this to the v0.16.0 milestone Nov 1, 2023
oscbyspro added a commit that referenced this issue Nov 1, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Nov 1, 2023

It's a bit awkward that unsigned integers may return optionals, but it's fine because you should never have to use this initializer when you know the integer is unsigned. It's meant for generic contexts where the integer's signedness is unspecified.

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