xref: /netbsd-src/common/lib/libprop/prop_number.3 (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1.\"	$NetBSD: prop_number.3,v 1.7 2007/08/16 16:31:00 thorpej Exp $
2.\"
3.\" Copyright (c) 2006 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Jason R. Thorpe.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in the
16.\" documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\" must display the following acknowledgement:
19.\" This product includes software developed by the NetBSD
20.\" Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\" contributors may be used to endorse or promote products derived
23.\" from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd October 11, 2006
38.Dt PROP_NUMBER 3
39.Os
40.Sh NAME
41.Nm prop_number ,
42.Nm prop_number_create_integer ,
43.Nm prop_number_create_unsigned_integer ,
44.Nm prop_number_copy ,
45.Nm prop_number_size ,
46.Nm prop_number_unsigned ,
47.Nm prop_number_integer_value ,
48.Nm prop_number_unsigned_integer_value ,
49.Nm prop_number_equals ,
50.Nm prop_number_equals_integer ,
51.Nm prop_number_equals_unsigned_integer
52.Nd numeric value property object
53.Sh LIBRARY
54.Lb libprop
55.Sh SYNOPSIS
56.In prop/proplib.h
57.\"
58.Ft prop_number_t
59.Fn prop_number_create_integer "int64_t val"
60.Ft prop_number_t
61.Fn prop_number_create_unsigned_integer "uint64_t val"
62.Ft prop_number_t
63.Fn prop_number_copy "prop_number_t number"
64.\"
65.Ft int
66.Fn prop_number_size "prop_number_t number"
67.Ft bool
68.Fn prop_number_unsigned "prop_number_t number"
69.Ft int64_t
70.Fn prop_number_integer_value "prop_number_t number"
71.Ft uint64_t
72.Fn prop_number_unsigned_integer_value "prop_number_t number"
73.\"
74.Ft bool
75.Fn prop_number_equals "prop_number_t num1" "prop_number_t num2"
76.Ft bool
77.Fn prop_number_equals_integer "prop_number_t number" "int64_t val"
78.Ft bool
79.Fn prop_number_equals_unsigned_integer "prop_number_t number" "uint64_t val"
80.Sh DESCRIPTION
81The
82.Nm prop_number
83family of functions operate on a numeric value property object type.
84Values are either signed or unsigned, and promoted to a 64-bit type
85.Pq int64_t or uint64_t , respectively .
86.Pp
87It is possible to compare number objects that differ in sign.
88Such comparisons first test to see if each object is within the valid
89number range of the other:
90.Bl -bullet
91.It
92Signed numbers that are greater than or equal to 0 can be compared to
93unsigned numbers.
94.It
95Unsigned numbers that are less than or equal to the largest signed 64-bit
96value
97.Pq Dv INT64_MAX
98can be compared to signed numbers.
99.El
100.Pp
101Number objects have a different externalized representation depending
102on their sign:
103.Bl -bullet
104.It
105Signed numbers are externalized in base-10
106.Pq decimal .
107.It
108Unsigned numbers are externalized in base-16
109.Pq hexadecimal .
110.El
111.Pp
112When numbers are internalized, the sign of the resulting number object
113.Pq and thus its valid range
114is determined by a set of rules evaluated in the following order:
115.Bl -bullet
116.It
117If the first character of the number is a
118.Sq -
119then the number is signed.
120.It
121If the first two characters of the number are
122.Sq 0x
123then the number is unsigned.
124.It
125If the number value fits into the range of a signed number then the
126number is signed.
127.It
128In all other cases, the number is unsigned.
129.El
130.Bl -tag -width "xxxxx"
131.It Fn prop_number_create_integer "int64_t val"
132Create a numeric value object with the signed value
133.Fa val .
134.It Fn prop_number_create_unsigned_integer "uint64_t val"
135Create a numeric value object with the unsigned value
136.Fa val .
137.It Fn prop_number_copy "prop_number_t number"
138Copy a numeric value object.
139.It Fn prop_number_size "prop_number_t number"
140Returns 8, 16, 32, or 64, representing the number of bits required to
141hold the value of the object.
142.It Fn prop_number_unsigned "prop_number_t number"
143Returns
144.Dv true
145if the numeric value object has an unsigned value.
146.It Fn prop_number_integer_value "prop_number_t number"
147Returns the signed integer value of the numeric value object.
148.It Fn prop_number_unsigned_integer_value "prop_number_t number"
149Returns the unsigned integer value of the numeric value object.
150.It Fn prop_number_equals "prop_number_t num1" "prop_number_t num2"
151Returns
152.Dv true
153if the two numeric value objects are equivalent.
154.It Fn prop_number_equals_integer "prop_number_t number" "int64_t val"
155Returns
156.Dv true
157if the object's value is equivalent to the signed value
158.Fa val .
159.It Fn prop_number_equals_unsigned_integer "prop_number_t number" \
160    "uint64_t val"
161Returns
162.Dv true
163if the object's value is equivalent to the unsigned value
164.Fa val .
165.El
166.Sh SEE ALSO
167.Xr prop_array 3 ,
168.Xr prop_bool 3 ,
169.Xr prop_data 3 ,
170.Xr prop_dictionary 3 ,
171.Xr prop_object 3 ,
172.Xr prop_string 3 ,
173.Xr proplib 3
174.Sh HISTORY
175The
176.Nm proplib
177property container object library first appeared in
178.Nx 4.0 .
179