Skip to content
IntLog2WithError

IntLog2WithError

Description

Compute floor(log2(value)).

Parameters

Name Direction Description
value in Integer to inspect
error out Optional pointer set to true on failure and false on success

Returns

Index of the highest set bit, or 0 on failure.

Usage example (Cross-references)

Usage examples (Cross-references)
    }
    
    u64 IntLog2WithError(Int *value, bool *error) {
        u64  out = 0;
        bool ok  = IntTryLog2(value, &out);
    
    static inline u64 MISRA_PRIV_IntLog2NoError(Int *value) {
        return IntLog2WithError(value, NULL);
    }
    
    #define MISRA_PRIV_INT_LOG2_SELECT(_1, _2, NAME, ...) NAME
    #define IntLog2(...) MISRA_PRIV_INT_LOG2_SELECT(__VA_ARGS__, IntLog2WithError, MISRA_PRIV_IntLog2NoError)(__VA_ARGS__)
    
    #endif // MISRA_STD_CONTAINER_INT_ACCESS_H
Last updated on