]> git.saurik.com Git - apple/cf.git/blob - CFBigNumber.h
CF-855.14.tar.gz
[apple/cf.git] / CFBigNumber.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 /* CFBigNumber.h
25 Copyright (c) 2012-2013, Apple Inc. All rights reserved.
26 */
27
28 #if !defined(__COREFOUNDATION_CFBIGNUMBER__)
29 #define __COREFOUNDATION_CFBIGNUMBER__ 1
30
31 #include <CoreFoundation/CFBase.h>
32 #include <CoreFoundation/CFNumber.h>
33
34
35 // Base 1 billion number: each digit represents 0 to 999999999
36 typedef struct {
37 uint32_t digits[5];
38 int32_t sign:8;
39 uint32_t __:24;
40 } _CFBigNum;
41
42 void _CFBigNumInitWithInt8(_CFBigNum *r, int8_t inNum);
43 void _CFBigNumInitWithInt16(_CFBigNum *r, int16_t inNum);
44 void _CFBigNumInitWithInt32(_CFBigNum *r, int32_t inNum);
45 void _CFBigNumInitWithInt64(_CFBigNum *r, int64_t inNum);
46 #ifdef __LP64__
47 void _CFBigNumInitWithInt128(_CFBigNum *r, __int128_t inNum);
48 #endif
49
50 void _CFBigNumInitWithUInt8(_CFBigNum *r, uint8_t inNum);
51 void _CFBigNumInitWithUInt16(_CFBigNum *r, uint16_t inNum);
52 void _CFBigNumInitWithUInt32(_CFBigNum *r, uint32_t inNum);
53 void _CFBigNumInitWithUInt64(_CFBigNum *r, uint64_t inNum);
54 #ifdef __LP64__
55 void _CFBigNumInitWithUInt128(_CFBigNum *r, __uint128_t inNum);
56 #endif
57
58 int8_t _CFBigNumGetInt8(const _CFBigNum *num);
59 int16_t _CFBigNumGetInt16(const _CFBigNum *num);
60 int32_t _CFBigNumGetInt32(const _CFBigNum *num);
61 int64_t _CFBigNumGetInt64(const _CFBigNum *num);
62 #ifdef __LP64__
63 __int128_t _CFBigNumGetInt128(const _CFBigNum *num);
64 #endif
65
66 uint8_t _CFBigNumGetUInt8(const _CFBigNum *num);
67 uint16_t _CFBigNumGetUInt16(const _CFBigNum *num);
68 uint32_t _CFBigNumGetUInt32(const _CFBigNum *num);
69 uint64_t _CFBigNumGetUInt64(const _CFBigNum *num);
70 #ifdef __LP64__
71 __uint128_t _CFBigNumGetUInt128(const _CFBigNum *num);
72 #endif
73
74 void _CFBigNumInitWithCFNumber(_CFBigNum *r, CFNumberRef input);
75 void _CFBigNumInitWithBytes(_CFBigNum *r, const void *bytes, CFNumberType type);
76 CFNumberRef _CFNumberCreateWithBigNum(const _CFBigNum *input);
77
78
79 CFComparisonResult _CFBigNumCompare(const _CFBigNum *a, const _CFBigNum *b);
80
81 void _CFBigNumNeg(_CFBigNum *r, const _CFBigNum *a);
82 uint8_t _CFBigNumAdd(_CFBigNum *r, const _CFBigNum *a, const _CFBigNum *b);
83 uint8_t _CFBigNumSub(_CFBigNum *r, const _CFBigNum *a, const _CFBigNum *b);
84
85
86 void _CFBigNumToCString(const _CFBigNum *vp, Boolean leading_zeros, Boolean leading_plus, char *buffer, size_t buflen);
87 void _CFBigNumFromCString(_CFBigNum *r, const char *string);
88
89 char *_CFBigNumCopyDescription(const _CFBigNum *num); // caller must free() returned ptr
90
91
92 #endif /* ! __COREFOUNDATION_CFBIGNUMBER__ */
93