opnsense-src/lib/libc/stdbit/stdc_bit_width.3
Robert Clausecker 27de6568a3 libc/stdbit: add man pages for stdbit functions
This adds man pages for each group of functions in <stdbit.h>.
The man pages have cross references to one-another.
Cross references from external man pages to these will be added
in a later commit.

Reviewed by:	pauamma@gundo.com, kib
Approved by:	markj (mentor)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D53659

(cherry picked from commit d790b16bbf0c3055ef00200d01659dfb3c0e5e5e)
2026-01-01 21:57:32 +01:00

104 lines
2 KiB
Groff

.\"
.\" Copyright (c) 2025 Robert Clausecker <fuz@FreeBSD.org>
.\"
.\" SPDX-License-Identifier: BSD-2-Clause
.\"
.Dd November 9, 2025
.Dt STDC_BIT_WIDTH 3
.Os
.Sh NAME
.Nm stdc_bit_width
.Nd find the first trailing one in an intege
.Sh SYNOPSIS
.Lb libc
.In stdbit.h
.Ft unsigned int
.Fn stdc_bit_width_uc "unsigned char value"
.Ft unsigned int
.Fn stdc_bit_width_us "unsigned short value"
.Ft unsigned int
.Fn stdc_bit_width_ui "unsigned int value"
.Ft unsigned int
.Fn stdc_bit_width_ul "unsigned long value"
.Ft unsigned int
.Fn stdc_bit_width_ull "unsigned long long value"
.Ft unsigned int
.Fn stdc_bit_width "value"
.Sh DESCRIPTION
The
.Nm stdc_bit_width_ Ns Em type Ns ()
family of functions returns the number of bits needed to represent
.Fa value ,
where
.Fa value
is of type
.Va unsigned char ,
.Va unsigned short ,
.Va unsigned int ,
.Va unsigned long ,
or
.Va unsigned long long
for
.Em type
being
.Sy uc ,
.Sy us ,
.Sy ui ,
.Sy ul ,
or
.Sy ull
respectively.
The
.Fn stdc_bit_width "value"
type-generic macro picks the appropriate
.Nm stdc_bit_width_ Ns Em type Ns ()
function based on the type of
.Fa value .
.Pp
Functions
.Fn stdc_bit_width_ui ,
.Fn stdc_bit_width_ul ,
and
.Fn stdc_bit_width_ull
are identical to
.Bx 4.3
functions
.Xr fls 3 ,
.Xr flsl 3 ,
and
.Xr flsll 3
respectively, except for operating on unsigned instead of signed values.
.Sh RETURN VALUES
Returns the least number of bits needed to represent
.Fa value .
If
.Fa value
is zero, the return value is zero.
Otherwise it is
.EQ
1 + \(lf log sub 2 italic value \(rf .
.EN
.Sh SEE ALSO
.Xr bit_fls 3 ,
.Xr fls 3 ,
.Xr flsl 3 ,
.Xr flsll 3 ,
.Xr stdbit 3 ,
.Xr stdc_count_leading_zeros 3 ,
.Xr stdc_first_leading_one 3
.Sh STANDARDS
The
.Nm stdc_bit_width_ Ns Em type Ns ()
family of functions and the
.Fn stdc_bit_width
type-generic macro conform to
.St -isoC-2023 .
.Sh HISTORY
The
.Nm stdc_bit_width_ Ns Em type Ns ()
family of functions and the
.Fn stdc_bit_width
type-generic macro were added in
.Fx 15.1.
.Sh AUTHOR
.An Robert Clausecker Aq Mt fuz@FreeBSD.org