aboutsummaryrefslogtreecommitdiff
path: root/Foundation/GTMNSNumber+64Bit.m
blob: 49d5c4d85a8248c8d9b134e897b1dab4c1cd5c01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
//  GTMNSNumber+64Bit.m
//
//  Copyright 2009 Google Inc.
//
//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
//  use this file except in compliance with the License.  You may obtain a copy
//  of the License at
// 
//  http://www.apache.org/licenses/LICENSE-2.0
// 
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
//  License for the specific language governing permissions and limitations under
//  the License.
//

#import "GTMNSNumber+64Bit.h"

@implementation NSNumber (GTM64BitAdditions)
+ (NSNumber *)gtm_numberWithCGFloat:(CGFloat)value {
  return [[[[self class] alloc] gtm_initWithCGFloat:value] autorelease];
}

+ (NSNumber *)gtm_numberWithInteger:(NSInteger)value {
  return [[[[self class] alloc] gtm_initWithInteger:value] autorelease];
}

+ (NSNumber *)gtm_numberWithUnsignedInteger:(NSUInteger)value {
  return [[[[self class] alloc] gtm_initWithUnsignedInteger:value] autorelease];
}

#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5

- (id)gtm_initWithCGFloat:(CGFloat)value {
  CFNumberRef numberRef = CFNumberCreate(NULL, kCFNumberCGFloatType, &value);
  return NSMakeCollectable(numberRef);
}

- (CGFloat)gtm_cgFloatValue {
  CGFloat value = 0;
  CFNumberGetValue((CFNumberRef)self, kCFNumberCGFloatType, &value);
  return value;
}

- (id)gtm_initWithInteger:(NSInteger)value {
  return [self initWithInteger:value];
}

- (NSInteger)gtm_integerValue {
  return [self integerValue];
}

- (id)gtm_initWithUnsignedInteger:(NSUInteger)value {
  return [self initWithUnsignedInteger:value];
}

- (NSUInteger)gtm_unsignedIntegerValue {
  return [self unsignedIntegerValue];
}

#else  // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5

- (id)gtm_initWithCGFloat:(CGFloat)value {
#if defined(__LP64__) && __LP64__
  return [self initWithDouble:value];
#else 
  return [self initWithFloat:value];
#endif  // defined(__LP64__) && __LP64__
}

- (CGFloat)gtm_cgFloatValue {
#if defined(__LP64__) && __LP64__
  return [self doubleValue];
#else 
  return [self floatValue];
#endif  // defined(__LP64__) && __LP64__
}

- (id)gtm_initWithInteger:(NSInteger)value {
  return [self initWithLong:value];
}

- (NSInteger)gtm_integerValue {
  return [self longValue];
}

- (id)gtm_initWithUnsignedInteger:(NSUInteger)value {
  return [self initWithUnsignedLong:value];
}

- (NSUInteger)gtm_unsignedIntegerValue {
  return [self unsignedLongValue];
}

#endif  // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
@end