oscbyspro / Ultimathnum

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

Miscellaneous 0.9.0 stuff #66

Closed oscbyspro closed 6 days ago

oscbyspro commented 1 month ago

I'll use this thread to document various minor changes.

oscbyspro commented 1 month ago

I'll disambiguate the following BinaryInteger.init(load:) cases:

let ix = IX.random()
let ux = UX.random()

IX(load: InfiniInt<IX>(load: ix))
IX(load: InfiniInt<UX>(load: ix))
UX(load: InfiniInt<IX>(load: ux))
UX(load: InfiniInt<UX>(load: ux))

IX(load: DoubleInt<IX>(load: ix))
IX(load: DoubleInt<UX>(load: ix))
UX(load: DoubleInt<IX>(load: ux))
UX(load: DoubleInt<UX>(load: ux))
oscbyspro commented 1 month ago

I'll rename T.Failure as T.Error. I see it as Value & Error vs Success & Failure and I want to be consistent about it.

oscbyspro commented 3 weeks ago

Seems silly, but going from A to B improves decoding performance ~2x (for small integers).

This is in a TextInt extension:
// MARK: A (slow)

try description.withUTF8(self.decode)

// MARK: B (fast)

try description.withUTF8 {
    try self.decode($0)
}
oscbyspro commented 1 week ago

The GCD stuff is a bit awkward to use in some generic contexts. I'll have a look a that, and perhaps hoist them like ilog2() and isqrt(). I also think it would be better if guarantee types mimicked their payload types w.r.t. instance vs static methods.

oscbyspro commented 1 week ago

Hm. Seems like I'll have to correct some change-of-sign stuff now that BinaryInteger/bezout(_:) permits signed values.

oscbyspro commented 1 week ago

I'll make TextInt's initializers generic over BinaryInteger but keep the UX default. I'll also change the radix output type to U8. The preferred concrete types minimize the need for size-related validation. The generics will remove the need for explicit type conversions.

oscbyspro commented 6 days ago

I'll add the following convenience conversions, which I performed manually in (#83).

extension BinaryInteger {
    @inlinable public static func exactly<Other>(
        _ source: consuming Fallible<Other>
    ) -> Fallible<Self> where Other: BinaryInteger { ... }

    @inlinable public static func exactly<Other>(
        sign: consuming Sign = .plus,
        magnitude: consuming Fallible<Other>
    ) -> Fallible<Self> where Other: UnsignedInteger { ... }
}

These should really be borrowing but that is not quite possible in ≤ Swift 5.10.