oscbyspro / Numberick

An arithmagick overhaul in Swift
Apache License 2.0
15 stars 3 forks source link

Req. `init?(magnitude:)` #107

Closed oscbyspro closed 1 year ago

oscbyspro commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.