Closed oscbyspro closed 1 month ago
The negative truncation behavior assumes Count.infinity: log2(&0+1)
is a power of 2. That's fine, and perhaps even desirable, since that makes every binary integer a power of 2. I suppose I'll take a moment to consider if this log2(&0+1)
definition has any obviously negative consequences. Edit: It looks like I've already documented this binary integer size-is-power-of-2 definition. I'm not surprised because it makes infinite sense. That's the reason Count
is 1's-complement-y. I need a vacation.
Question: Why does Count.exactly(IX.min)
return nil
?
Answer: Because bit patterns in the finite-to-infinite gap don't preserve BinaryInteger.exactly(_:)
semantics.
Note that Count
can't implement init(load:)
. It's neither a BinaryInteger
nor a Guarantee
but Count.exactly(_:)
is more powerful than Count.init(exactly:)
(and somewhat trickier to implement) so I'd argue its functionality is preferred. Edit: I suppose it could implement an optional init?(load:)
.
I'll also add Count.init?(load: some BinaryInteger)
because it makes the binary-integer-esque shape clearer.
I've tried out various forms of
Guarantee
protocols, and there's no reasonable way to conformCount
to any of them. So, I've concluded that it's better to shape it in the likeness ofBinaryInteger
instead. Its validation function should therefore be (#95):Changes
I'll remove
Count.init(exactly:)
, etc, and add a few methods similar to this:Alternatives
The only other
A-> Optional<Fallible<B>>
conversion isBinaryInteger.leniently(some Swift.BinaryFloatingPoint)
, so I might consider using that signature and lettingexactly(_:)
returnOptional<Self>
instead. The problem is that the proposed version has the exact same semantics asBinaryInteger.exactly(_:)
for all non-nil values.