STDC_BIT_CEIL(3)
π STDC_BIT_CEIL(3) β like, the round-up-to-the-next-power-of-2 page, bestie
okay so this is STDC_BIT_CEIL(3) from the Library Functions Manual, and it is literally the "round up to the next power of 2" era and we are obsessed. come sit with me, this one's short and it ate. β¨
πΈ NAME πΈ
stdc_bit_ceil β round up to the next power of 2
no cap, that's the whole vibe. you hand it a number, it hands you back the next power of 2 going up. queen behavior. π
π SYNOPSIS π
Standard C Library (libc, -lc)
#include <stdbit.h>
unsigned char
stdc_bit_ceil_uc(unsigned char value);
unsigned short
stdc_bit_ceil_us(unsigned short value);
unsigned int
stdc_bit_ceil_ui(unsigned int value);
unsigned long
stdc_bit_ceil_ul(unsigned long value);
unsigned long long
stdc_bit_ceil_ull(unsigned long long value);
typeof(value)
stdc_bit_ceil(value);
like yes, there are five whole tiny functions plus the type-generic macro, and every single one of them is serving. π
π¦ DESCRIPTION π¦
so the stdc_bit_ceil_type() family of functions rounds value up to the next power of 2, where value is of type unsigned char, unsigned short, unsigned int, unsigned long, or unsigned long long for type being uc, us, ui, ul, or ull respectively. six-letter lore, iykyk. π
and the stdc_bit_ceil(value) type-generic macro? she's the main character β she picks the appropriate stdc_bit_ceil_type() function based on the type of value. literally does the matching for you so you don't have to. π«Ά
ok but the way this is genuinely convenient β one name, five types, zero thoughts required. periodt.
β RETURN VALUES β
Returns value rounded up to the next power of 2. and if that value is not representable? you get 0 back. that's it, that's the whole answer. π (yes, 0 is the "nope, can't do it" signal here, so clock it.)
π₯ SEE ALSO π₯
the floor version is her sibling and yes you should read both, bestie. they're a package deal. π
π STANDARDS π
The stdc_bit_ceil_type() family of functions and the stdc_bit_ceil() type-generic macro conform to .
(yes, the citation in the page is literally just blank after "conform to" β not me forgetting, that's how it shipped π)
πΈ HISTORY πΈ
The stdc_bit_ceil_type() family of functions and the stdc_bit_ceil() type-generic macro were added in FreeBSD 15.1. she's new here and she's already iconic. β¨
π AUTHOR π
Robert Clausecker <fuz@FreeBSD.org>
give her a round of applause fr fr π«Ά
and that's the page!! tysm for reading, ily, go round some bits up π
this cutie was brought to you by the Debian crew, dated November 9, 2025 β signing off π
π¦ 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