oscbyspro / Ultimathnum

Binary arithmetic reimagined in Swift
Apache License 2.0
9 stars 1 forks source link

Add: SystemsInteger.division(unchecked:by:) #113

Open oscbyspro opened 1 month ago

oscbyspro commented 1 month ago

I haven't added NaturalInteger (#112) yet, but I noticed one more thing: I could efficiently derive a safe 2-by-1 division algorithm from an unsafe protocol requirement. It might reduce some overhead in other algorithms. I've also considered a more elaborate Guarantee-esque (#62) approach, but I don't think it would add much value in this case.

protocol NaturalInteger {
    @unsafe @inlinable static func division(unchecked dividend: Doublet<Self>, by divisor: Nonzero<Self>) -> Division<Self, Self>
}

Of note, I don't believe the 2-by-1 standard library algorithm is a built-in so I could perhaps roll my own at some point.