xref: /freebsd/lib/libc/stdbit/stdc_bit_floor.3 (revision d790b16bbf0c3055ef00200d01659dfb3c0e5e5e)
1.\"
2.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
3.\"
4.\" SPDX-License-Identifier: BSD-2-Clause
5.\"
6.Dd November 9, 2025
7.Dt STDC_BIT_FLOOR 3
8.Os
9.Sh NAME
10.Nm stdc_bit_floor
11.Nd round down to the previous power of\~2
12.Sh SYNOPSIS
13.Lb libc
14.In stdbit.h
15.Ft unsigned char
16.Fn stdc_bit_floor_uc "unsigned char value"
17.Ft unsigned short
18.Fn stdc_bit_floor_us "unsigned short value"
19.Ft unsigned int
20.Fn stdc_bit_floor_ui "unsigned int value"
21.Ft unsigned long
22.Fn stdc_bit_floor_ul "unsigned long value"
23.Ft unsigned long long
24.Fn stdc_bit_floor_ull "unsigned long long value"
25.Ft typeof Ns Pq Em value
26.Fn stdc_bit_floor "value"
27.Sh DESCRIPTION
28The
29.Nm stdc_bit_floor_ Ns Em type Ns ()
30family of functions rounds
31.Fa value
32down to the previous power of\~2, where
33.Fa value
34is of type
35.Va unsigned char ,
36.Va unsigned short ,
37.Va unsigned int ,
38.Va unsigned long ,
39or
40.Va unsigned long long
41for
42.Em type
43being
44.Sy uc ,
45.Sy us ,
46.Sy ui ,
47.Sy ul ,
48or
49.Sy ull
50respectively.
51The
52.Fn stdc_bit_floor "value"
53type-generic macro picks the appropriate
54.Nm stdc_bit_floor_ Ns Em type Ns ()
55function based on the type of
56.Fa value .
57.Sh RETURN VALUES
58Returns
59.Fa value
60round down to the previous power of\~2.
61If
62.Fa value
63is equal to zero,
64zero is returned.
65.Sh SEE ALSO
66.Xr stdbit 3 ,
67.Xr stdc_bit_ceil 3
68.Sh STANDARDS
69The
70.Nm stdc_bit_floor_ Ns Em type Ns ()
71family of functions and the
72.Fn stdc_bit_floor
73type-generic macro conform to
74.St -isoC-2023 .
75.Sh HISTORY
76The
77.Nm stdc_bit_floor_ Ns Em type Ns ()
78family of functions and the
79.Fn stdc_bit_floor
80type-generic macro were added in
81.Fx 15.1.
82.Sh AUTHOR
83.An Robert Clausecker Aq Mt fuz@FreeBSD.org
84