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

Function proposition: Add Function lowestBitValue #536

Closed
Robert42 opened this issue Aug 5, 2016 · 1 comment
Closed

Function proposition: Add Function lowestBitValue #536

Robert42 opened this issue Aug 5, 2016 · 1 comment
Assignees
Milestone

Comments

@Robert42
Copy link

Robert42 commented Aug 5, 2016

We've already got a function highestBitValue

template <typename genIUType>
GLM_FUNC_QUALIFIER genIUType highestBitValue(genIUType Value)
{
    genIUType tmp = Value;
    genIUType result = genIUType(0);
    while(tmp)
    {
        result = (tmp & (~tmp + 1)); // grab lowest bit
        tmp &= ~result; // clear lowest bit
    }
    return result;
}

I think an additional function lowestBitValue might be also useful for users (I needed it when using an bitfield as set, and I wanted to iterate over it)

template <typename genIUType>
GLM_FUNC_QUALIFIER genIUType lowestBitValue(genIUType Value)
{
    return (Value & (~Value + 1)); // grab lowest bit
}

template <typename genIUType>
GLM_FUNC_QUALIFIER genIUType highestBitValue(genIUType Value)
{
    genIUType tmp = Value;
    genIUType result = genIUType(0);
    while(tmp)
    {
        result = lowestBitValue(tmp); // grab lowest bit
        tmp &= ~result; // clear lowest bit
    }
    return result;
}
@Groovounet Groovounet added this to the GLM 0.9.8 milestone Aug 7, 2016
@Groovounet Groovounet self-assigned this Aug 7, 2016
Groovounet added a commit that referenced this issue Aug 7, 2016
@Groovounet
Copy link
Member

This feature has been added in GLM 0.9.8 for GLM 0.9.8.0 release.

Thanks for reporting,
Christophe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants