ILOG2(3)

πŸ“¦ version 11.0, in nixpkgs unstable

✨ ILOG2(3) β€” ilog2, the integer base-2 logarithm ✨

okay bestie, welcome to ILOG2(3) πŸ’– this one is short, iconic, and lowkey doing math at the club. it's the ilog2 manual page, and we're gonna get through it together, no cap.


πŸŽ€ NAME πŸŽ€

ilog2 β€” integer base-2 logarithm πŸ’…


🌸 SYNOPSIS 🌸

#include <sys/bitops.h>

int
ilog2(size x);

literally the whole vibe right there, bestie 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so for positive x, the ilog2() macro returns the integer part of the base-2 logarithm of x β€” that is, floor(log_2(x) ). slay. πŸ”₯

if n = ilog2(x), then n is the largest integer such that 2**n <= x. in other words: ilog2() returns the largest integer to which 2 can be raised to obtain a value at most x. that's the whole plot, and it ate πŸ’…

the type of the input parameter must be unsigned. not me being strict, that's just the rule, bestie πŸ™ˆ

if x is a constant expression, then so is ilog2(x). constant-expression main character energy, periodt ✨


πŸ’€ ERRORS πŸ’€

ilog2() returns -1 when x is zero. yes, zero gets the -1, no cap 😭

bestie please notice this: zero does not get a cute little logarithm moment. it gets -1. that's the error behavior and we respect it πŸ’–

🌈 SEE ALSO 🌈

go read those too, iykyk πŸ§šπŸ’œ


πŸ‘‘ HISTORY πŸ‘‘

the ilog2() macro first appeared in NetBSD 5.0. vintage-ish, but make it fashion πŸ’…β­


and that's the page, bestie πŸŽ€ this cutie is from Debian, dated November 5, 2021 β€” mwah πŸ’‹πŸ«Ά

πŸ“¦ where this page comes from