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

Success

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

Failure

Returns 0 when value is zero. *error (if non-NULL) is set to true.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    static inline u64 int_log2_no_error(const Int *value) {
        return IntLog2WithError(value, NULL);
    }
    /// TAGS: Int, Access, Log2, Macro
    ///
    #define IntLog2(...) INT_LOG2_SELECT(__VA_ARGS__, IntLog2WithError, int_log2_no_error)(__VA_ARGS__)
    
    #endif // MISRA_STD_CONTAINER_INT_ACCESS_H
    }
    
    u64 IntLog2WithError(const Int *value, bool *error) {
        u64  out = 0;
        bool ok  = IntTryLog2(value, &out);
Last updated on