ObjFW  Check-in [8eb830d7c8]

Overview
Comment:Remove long double from OFNumber as there's no type encoding for it.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8eb830d7c818fcb04e2b3849421842779d6a2c13bb5cebf88dbf387c83dd6665
User & Date: js on 2009-04-19 23:17:17
Other Links: manifest | tags
Context
2009-04-19
23:19
More methods for OFNumber. check-in: 1898ec5a4b user: js tags: trunk
23:17
Remove long double from OFNumber as there's no type encoding for it. check-in: 8eb830d7c8 user: js tags: trunk
20:34
Use isa instead of [self class]. check-in: 139591afe1 user: js tags: trunk
Changes

Modified src/OFNumber.h from [6453b5d17a] to [9ea1dbd0dc].

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	OF_NUMBER_SSIZE,
	OF_NUMBER_INTMAX,
	OF_NUMBER_UINTMAX,
	OF_NUMBER_PTRDIFF,
	OF_NUMBER_INTPTR,
	OF_NUMBER_FLOAT,
	OF_NUMBER_DOUBLE,
	OF_NUMBER_LONG_DOUBLE
};

/**
 * The OFNumber class provides a way to store a number in an object and
 * manipulate it.
 */
@interface OFNumber: OFObject







<







34
35
36
37
38
39
40

41
42
43
44
45
46
47
	OF_NUMBER_SSIZE,
	OF_NUMBER_INTMAX,
	OF_NUMBER_UINTMAX,
	OF_NUMBER_PTRDIFF,
	OF_NUMBER_INTPTR,
	OF_NUMBER_FLOAT,
	OF_NUMBER_DOUBLE,

};

/**
 * The OFNumber class provides a way to store a number in an object and
 * manipulate it.
 */
@interface OFNumber: OFObject
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
		ssize_t	       ssize;
		intmax_t       intmax;
		uintmax_t      uintmax;
		ptrdiff_t      ptrdiff;
		intptr_t       intptr;
		float	       float_;
		double	       double_;
		long double    longdouble;
	} value;
	enum of_number_type type;
}

+ numberWithChar: (char)char_;
+ numberWithShort: (short)short_;
+ numberWithInt: (int)int_;







<







67
68
69
70
71
72
73

74
75
76
77
78
79
80
		ssize_t	       ssize;
		intmax_t       intmax;
		uintmax_t      uintmax;
		ptrdiff_t      ptrdiff;
		intptr_t       intptr;
		float	       float_;
		double	       double_;

	} value;
	enum of_number_type type;
}

+ numberWithChar: (char)char_;
+ numberWithShort: (short)short_;
+ numberWithInt: (int)int_;
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
+ numberWithSSize: (ssize_t)ssize;
+ numberWithIntMax: (intmax_t)intmax;
+ numberWithUIntMax: (uintmax_t)uintmax;
+ numberWithPtrDiff: (ptrdiff_t)ptrdiff;
+ numberWithIntPtr: (intptr_t)intptr;
+ numberWithFloat: (float)float_;
+ numberWithDouble: (double)double_;
+ numberWithLongDouble: (long double)longdouble;

- initWithChar: (char)char_;
- initWithShort: (short)short_;
- initWithInt: (int)int_;
- initWithLong: (long)long_;
- initWithUChar: (unsigned char)uchar;
- initWithUShort: (unsigned short)ushort;







<







95
96
97
98
99
100
101

102
103
104
105
106
107
108
+ numberWithSSize: (ssize_t)ssize;
+ numberWithIntMax: (intmax_t)intmax;
+ numberWithUIntMax: (uintmax_t)uintmax;
+ numberWithPtrDiff: (ptrdiff_t)ptrdiff;
+ numberWithIntPtr: (intptr_t)intptr;
+ numberWithFloat: (float)float_;
+ numberWithDouble: (double)double_;


- initWithChar: (char)char_;
- initWithShort: (short)short_;
- initWithInt: (int)int_;
- initWithLong: (long)long_;
- initWithUChar: (unsigned char)uchar;
- initWithUShort: (unsigned short)ushort;
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
- initWithSSize: (ssize_t)ssize;
- initWithIntMax: (intmax_t)intmax;
- initWithUIntMax: (uintmax_t)uintmax;
- initWithPtrDiff: (ptrdiff_t)ptrdiff;
- initWithIntPtr: (intptr_t)intptr;
- initWithFloat: (float)float_;
- initWithDouble: (double)double_;
- initWithLongDouble: (long double)longdouble;

- (enum of_number_type)type;

- (char)asChar;
- (short)asShort;
- (int)asInt;
- (long)asLong;







<







120
121
122
123
124
125
126

127
128
129
130
131
132
133
- initWithSSize: (ssize_t)ssize;
- initWithIntMax: (intmax_t)intmax;
- initWithUIntMax: (uintmax_t)uintmax;
- initWithPtrDiff: (ptrdiff_t)ptrdiff;
- initWithIntPtr: (intptr_t)intptr;
- initWithFloat: (float)float_;
- initWithDouble: (double)double_;


- (enum of_number_type)type;

- (char)asChar;
- (short)asShort;
- (int)asInt;
- (long)asLong;
151
152
153
154
155
156
157
158
159
- (ssize_t)asSSize;
- (intmax_t)asIntMax;
- (uintmax_t)asUIntMax;
- (ptrdiff_t)asPtrDiff;
- (intptr_t)asIntPtr;
- (float)asFloat;
- (double)asDouble;
- (long double)asLongDouble;
@end







<

147
148
149
150
151
152
153

154
- (ssize_t)asSSize;
- (intmax_t)asIntMax;
- (uintmax_t)asUIntMax;
- (ptrdiff_t)asPtrDiff;
- (intptr_t)asIntPtr;
- (float)asFloat;
- (double)asDouble;

@end

Modified src/OFNumber.m from [8e480899d7] to [1e5b23cc34].

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
		return (t)value.ptrdiff;				\
	case OF_NUMBER_INTPTR:						\
		return (t)value.intptr;					\
	case OF_NUMBER_FLOAT:						\
		return (t)value.float_;					\
	case OF_NUMBER_DOUBLE:						\
		return (t)value.double_;				\
	case OF_NUMBER_LONG_DOUBLE:					\
		return (t)value.longdouble;				\
	default:							\
		@throw [OFInvalidFormatException newWithClass: isa];	\
		return 0;	/* Make gcc happy */			\
	}

@implementation OFNumber
+ numberWithChar: (char)char_







<
<







60
61
62
63
64
65
66


67
68
69
70
71
72
73
		return (t)value.ptrdiff;				\
	case OF_NUMBER_INTPTR:						\
		return (t)value.intptr;					\
	case OF_NUMBER_FLOAT:						\
		return (t)value.float_;					\
	case OF_NUMBER_DOUBLE:						\
		return (t)value.double_;				\


	default:							\
		@throw [OFInvalidFormatException newWithClass: isa];	\
		return 0;	/* Make gcc happy */			\
	}

@implementation OFNumber
+ numberWithChar: (char)char_
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
}

+ numberWithDouble: (double)double_
{
	return [[[OFNumber alloc] initWithDouble: double_] autorelease];
}

+ numberWithLongDouble: (long double)longdouble
{
	return [[[OFNumber alloc] initWithLongDouble: longdouble] autorelease];
}

- initWithChar: (char)char_
{
	if ((self = [super init])) {
		value.char_ = char_;
		type = OF_NUMBER_CHAR;
	}








<
<
<
<
<







186
187
188
189
190
191
192





193
194
195
196
197
198
199
}

+ numberWithDouble: (double)double_
{
	return [[[OFNumber alloc] initWithDouble: double_] autorelease];
}






- initWithChar: (char)char_
{
	if ((self = [super init])) {
		value.char_ = char_;
		type = OF_NUMBER_CHAR;
	}

433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
		value.double_ = double_;
		type = OF_NUMBER_DOUBLE;
	}

	return self;
}

- initWithLongDouble: (long double)longdouble
{
	if ((self = [super init])) {
		value.longdouble = longdouble;
		type = OF_NUMBER_LONG_DOUBLE;
	}

	return self;
}

- (enum of_number_type)type
{
	return type;
}

- (char)asChar
{







<
<
<
<
<
<
<
<
<
<







426
427
428
429
430
431
432










433
434
435
436
437
438
439
		value.double_ = double_;
		type = OF_NUMBER_DOUBLE;
	}

	return self;
}











- (enum of_number_type)type
{
	return type;
}

- (char)asChar
{
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
	case OF_NUMBER_UINT64:
	case OF_NUMBER_SIZE:
	case OF_NUMBER_UINTMAX:
	case OF_NUMBER_INTPTR:
		return ([obj asUIntMax] == [self asUIntMax] ? YES : NO);
	case OF_NUMBER_FLOAT:
	case OF_NUMBER_DOUBLE:
	case OF_NUMBER_LONG_DOUBLE:
		return ([obj asLongDouble] == [self asLongDouble] ? YES : NO);
	default:
		@throw [OFInvalidArgumentException newWithClass: isa
						    andSelector: _cmd];
	}
}

- (uint32_t)hash
{
	return [self asUInt32];
}
@end







<
|











588
589
590
591
592
593
594

595
596
597
598
599
600
601
602
603
604
605
606
	case OF_NUMBER_UINT64:
	case OF_NUMBER_SIZE:
	case OF_NUMBER_UINTMAX:
	case OF_NUMBER_INTPTR:
		return ([obj asUIntMax] == [self asUIntMax] ? YES : NO);
	case OF_NUMBER_FLOAT:
	case OF_NUMBER_DOUBLE:

		return ([obj asDouble] == [self asDouble] ? YES : NO);
	default:
		@throw [OFInvalidArgumentException newWithClass: isa
						    andSelector: _cmd];
	}
}

- (uint32_t)hash
{
	return [self asUInt32];
}
@end