Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No minLastIndex[...] methods #136

Closed
oscbyspro opened this issue Jun 15, 2023 · 0 comments
Closed

No minLastIndex[...] methods #136

oscbyspro opened this issue Jun 15, 2023 · 0 comments
Labels
subtraction huh? where did it go?
Milestone

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Jun 15, 2023

From oscbyspro/Numberick#11

The method minLastIndexReportingIsZeroOrMinusOne() is only used once.

/// Returns the last index in reduced two's complement form, along with an
/// indicator of whether this value is zero or minus one. In the case where
/// this value is zero or minus one, the index is zero.
///
@inlinable public func minLastIndexReportingIsZeroOrMinusOne() -> (minLastIndex: Int, isZeroOrMinusOne: Bool) {
    let sign  = UInt(repeating: self.isLessThanZero)
    let index = self.lastIndex(where:{ $0 != sign })
    return index.map({( $0, false )}) ?? (Int.zero, true)
}

In the unsigned case it's almost identical to the following expression:

let minLastIndex = self.lastIndex(where:{ !$0.isZero }) ?? self.startIndex

I'll remove it because it's A) too simple and B) its semantics may not always be what you want. In some unsigned cases you might prefer if zero is considered empty. This becomes much more apparent if you consider methods like minBitWidth().

@oscbyspro oscbyspro added the subtraction huh? where did it go? label Jun 15, 2023
@oscbyspro oscbyspro added this to the v3.0.0 milestone Jun 15, 2023
oscbyspro added a commit that referenced this issue Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
subtraction huh? where did it go?
Projects
None yet
Development

No branches or pull requests

1 participant