STDC_BIT_FLOOR(3)
β¨ STDC_BIT_FLOOR(3) β your new fave libc page, section 3, library functions manual, mwah π
okay so bestie, buckle up, because this one is genuinely adorable. we're talking about stdc_bit_floor from the Standard C Library, aka libc, linked with -lc, and it's a whole little family of functions that round your number down to the previous power of 2. that's the vibe. π
π¦ SYNOPSIS π¦
here's the whole squad, look at them:
#include <stdbit.h>
unsigned char
stdc_bit_floor_uc(unsigned char value);
unsigned short
stdc_bit_floor_us(unsigned short value);
unsigned int
stdc_bit_floor_ui(unsigned int value);
unsigned long
stdc_bit_floor_ul(unsigned long value);
unsigned long long
stdc_bit_floor_ull(unsigned long long value);
typeof(value)
stdc_bit_floor(value);
no cap, that's the entire lineup. one for every size of unsigned int energy. π₯
π DESCRIPTION π
so the stdc_bit_floor_type() family of functions rounds value down to the previous power of 2. periodt. β¨
and value can be any of these types:
unsigned charβ that'stype=ucπunsigned shortβtype=usπΈunsigned intβtype=uiπ¦unsigned longβtype=ulπunsigned long longβtype=ullπ
and then there's stdc_bit_floor(value), the type-generic macro, which is giving main character energy fr fr β it just looks at the type of value and picks the appropriate stdc_bit_floor_type() function for you. you don't even have to think about it. it just knows. ππ«Ά
π RETURN VALUES π
it returns value rounded down to the previous power of 2. simple, iconic, no notes.
and if value is equal to zero? zero is returned. zero in, zero out, the most honest relationship you'll ever have. π
π₯ SEE ALSO π₯
go give these besties some love too:
stdbit(3)stdc_bit_ceil(3)β the other direction, the little overachiever π
β STANDARDS β
The stdc_bit_floor_type() family of functions and the stdc_bit_floor() type-generic macro conform to .
π§ HISTORY π§
The stdc_bit_floor_type() family of functions and the stdc_bit_floor() type-generic macro were added in FreeBSD 15.1. so they're lowkey new-ish, freshly dropped, and honestly? obsessed. π
π AUTHOR π
Robert Clausecker <fuz@FreeBSD.org> β thank you for your service, legend π«‘π
and that's the page!! mwah π this was Debian, dated November 9, 2025, signing off β STDC_BIT_FLOOR(3) forever, iykyk πΈβ¨π¦
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π the page's license: BSD-2-Clause
- Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms