Numberick icon indicating copy to clipboard operation
Numberick copied to clipboard

Between Numeric and BinaryInteger

Open oscbyspro opened this issue 2 years ago • 3 comments

I'd like to have a protocol that encompasses Signed<Magnitude> without shoehorning it down the binary integer protocol hierarchy. I imagine something like a numeric-but-divisible-and-convertible-thing-y. I haven't thought of the requirements yet, this is more like a todo-note.

oscbyspro avatar Sep 28 '23 14:09 oscbyspro

I'd also like to avoid making it integer specific, because that would make the un/signed integer protocols confusing (as they are binary).

oscbyspro avatar Sep 28 '23 14:09 oscbyspro

Hm. Most of the Signed<Magnitude> things I want to generalize are integer things, so I guess it would have to be integer related. Maybe I could call it something like basic or primitive since the un/signed protocols have established that binary is the default.

oscbyspro avatar Oct 04 '23 05:10 oscbyspro

There are some annoying things that come with trying to insert non-leaf protocols. Like, you get ambiguities if you try to customize existing BinaryInteger methods. It can be solved with additional overloads, however:

extension String {
    init(_ source: some NBKPlainInteger,                 radix: Int = 10, uppercase: Bool = false) { ... }
    init(_ source: some NBKPlainInteger & BinaryInteger, radix: Int = 10, uppercase: Bool = false) { ... }
}

oscbyspro avatar Oct 04 '23 10:10 oscbyspro