当前位置: C语言 -- 标准库 -- <stdbit.h> -- stdc_bit_ceil_ui

stdc_bit_ceil_ui函数


概要:
#include <stdbit.h>
unsigned int stdc_bit_ceil_ui(unsigned int value) [[unsequenced]];

描述:

该函数计算不小于参数value值的2的最小整数幂。如果结果超出了返回类型所能表示的范围,该函数将返回0。

unsequenced类型属性表示:stdc_bit_ceil_ui函数是无状态、无副作用、幂等、并且是独立的。


参数:
unsigned int value

参数为unsigned int类型对象。


返回值:

该函数返回不小于参数value值的2的最小整数幂。如果结果超出了返回类型所能表示的范围,该函数将返回0。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
/*函数stdc_bit_ceil_ui范例*/

#include <stdbit.h>
#include <stdio.h>

int main(void)
{
    unsigned int value = 0X5AU;

    printf("The smallest integral power of 2 that is not less than value: %u\n", \
    stdc_bit_ceil_ui(value));

    return 0;
}

可能输出:

The smallest integral power of 2 that is not less than value: 128

(注:编译时实现未支持<stdbit.h>头文件。)


相关内容:
stdc_bit_ceil_uc 计算不小于unsigned char类型指定值的2的最小整数幂的函数。
stdc_bit_ceil_us 计算不小于unsigned short类型指定值的2的最小整数幂的函数。
stdc_bit_ceil_ul 计算不小于unsigned long int类型指定值的2的最小整数幂的函数。
stdc_bit_ceil_ull 计算不小于unsigned long long int类型指定值的2的最小整数幂的函数。
stdc_bit_ceil 计算不小于指定值的2的最小整数幂的泛型函数。


主要参考资料:

1、ISO/IEC 9899:2024