]> git.saurik.com Git - apple/cf.git/blob - CFNumber.h
2249d9c729048d2dbdd52dce4da55326cf2b4b95
[apple/cf.git] / CFNumber.h
1 /*
2 * Copyright (c) 2014 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /* CFNumber.h
25 Copyright (c) 1999-2013, Apple Inc. All rights reserved.
26 */
27
28 #if !defined(__COREFOUNDATION_CFNUMBER__)
29 #define __COREFOUNDATION_CFNUMBER__ 1
30
31 #include <CoreFoundation/CFBase.h>
32
33 CF_IMPLICIT_BRIDGING_ENABLED
34 CF_EXTERN_C_BEGIN
35
36 typedef const struct __CFBoolean * CFBooleanRef;
37
38 CF_EXPORT
39 const CFBooleanRef kCFBooleanTrue;
40 CF_EXPORT
41 const CFBooleanRef kCFBooleanFalse;
42
43 CF_EXPORT
44 CFTypeID CFBooleanGetTypeID(void);
45
46 CF_EXPORT
47 Boolean CFBooleanGetValue(CFBooleanRef boolean);
48
49 typedef CF_ENUM(CFIndex, CFNumberType) {
50 /* Fixed-width types */
51 kCFNumberSInt8Type = 1,
52 kCFNumberSInt16Type = 2,
53 kCFNumberSInt32Type = 3,
54 kCFNumberSInt64Type = 4,
55 kCFNumberFloat32Type = 5,
56 kCFNumberFloat64Type = 6, /* 64-bit IEEE 754 */
57 /* Basic C types */
58 kCFNumberCharType = 7,
59 kCFNumberShortType = 8,
60 kCFNumberIntType = 9,
61 kCFNumberLongType = 10,
62 kCFNumberLongLongType = 11,
63 kCFNumberFloatType = 12,
64 kCFNumberDoubleType = 13,
65 /* Other */
66 kCFNumberCFIndexType = 14,
67 kCFNumberNSIntegerType CF_ENUM_AVAILABLE(10_5, 2_0) = 15,
68 kCFNumberCGFloatType CF_ENUM_AVAILABLE(10_5, 2_0) = 16,
69 kCFNumberMaxType = 16
70 };
71
72 typedef const struct __CFNumber * CFNumberRef;
73
74 CF_EXPORT
75 const CFNumberRef kCFNumberPositiveInfinity;
76 CF_EXPORT
77 const CFNumberRef kCFNumberNegativeInfinity;
78 CF_EXPORT
79 const CFNumberRef kCFNumberNaN;
80
81 CF_EXPORT
82 CFTypeID CFNumberGetTypeID(void);
83
84 /*
85 Creates a CFNumber with the given value. The type of number pointed
86 to by the valuePtr is specified by type. If type is a floating point
87 type and the value represents one of the infinities or NaN, the
88 well-defined CFNumber for that value is returned. If either of
89 valuePtr or type is an invalid value, the result is undefined.
90 */
91 CF_EXPORT
92 CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr);
93
94 /*
95 Returns the storage format of the CFNumber's value. Note that
96 this is not necessarily the type provided in CFNumberCreate().
97 */
98 CF_EXPORT
99 CFNumberType CFNumberGetType(CFNumberRef number);
100
101 /*
102 Returns the size in bytes of the type of the number.
103 */
104 CF_EXPORT
105 CFIndex CFNumberGetByteSize(CFNumberRef number);
106
107 /*
108 Returns true if the type of the CFNumber's value is one of
109 the defined floating point types.
110 */
111 CF_EXPORT
112 Boolean CFNumberIsFloatType(CFNumberRef number);
113
114 /*
115 Copies the CFNumber's value into the space pointed to by
116 valuePtr, as the specified type. If conversion needs to take
117 place, the conversion rules follow human expectation and not
118 C's promotion and truncation rules. If the conversion is
119 lossy, or the value is out of range, false is returned. Best
120 attempt at conversion will still be in *valuePtr.
121 */
122 CF_EXPORT
123 Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr);
124
125 /*
126 Compares the two CFNumber instances. If conversion of the
127 types of the values is needed, the conversion and comparison
128 follow human expectations and not C's promotion and comparison
129 rules. Negative zero compares less than positive zero.
130 Positive infinity compares greater than everything except
131 itself, to which it compares equal. Negative infinity compares
132 less than everything except itself, to which it compares equal.
133 Unlike standard practice, if both numbers are NaN, then they
134 compare equal; if only one of the numbers is NaN, then the NaN
135 compares greater than the other number if it is negative, and
136 smaller than the other number if it is positive. (Note that in
137 CFEqual() with two CFNumbers, if either or both of the numbers
138 is NaN, true is returned.)
139 */
140 CF_EXPORT
141 CFComparisonResult CFNumberCompare(CFNumberRef number, CFNumberRef otherNumber, void *context);
142
143 CF_EXTERN_C_END
144 CF_IMPLICIT_BRIDGING_DISABLED
145
146 #endif /* ! __COREFOUNDATION_CFNUMBER__ */
147