ObjFW  Diff

Differences From Artifact [57186c2c7a]:

To Artifact [17a849254e]:


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
99
100
101

102
103
104

105
106
107
108
109
110
111
112
113



114
115
116
117
118
119
120
121
122

123
124
125
126
127
128
129
130
131
132
133







134
135
136
137
138
139
140
141
142

143
144
145

146
147
148

149
150
151


152
153
154
155
156
157

158
159
160
161
162
163



164
165
166
167
168

169
170

171
172
173
174




175
176
177
178
179
180
181

182
183
184

185
186

187
188

189
190
191

192
193
194

195
196

197
198

199
200
201
202
203
204
205

206
207
208

209
210

211
212
213
214
215
216




217
218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
233
234
235
236
237
238

239
240
241
242

243
244
245
246
247
248
249




250
251
252
253
254
255
256

257
258
259

260
261
262
263





264
265

266
267
268
269
270
271
272

273
274
275

276
277

278
279
280
281
282
283




284
285
286
287
288
289
290
291
292

293
294
295
296
297
298


299
300
301




302
303

304
305
306
307
308
309
310
311
312

313
314

315
316
317
318

319
320
321

322
323

324
325
326
327
328



329
330

331
332

333
334
335
336
337

338
339
340
341
342
343
344

345
346

347
348
349
350
351
352




353
354
355
356
357
358
359
360
361
362
363

364
365
366
367
368
369
370
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









99
100
101
102
103
104
105
106








107
108
109

110
111


112
113


114
115
116





117






118
119
120





121
122

123




124
125
126
127
128






129
130
131

132
133

134


135



136



137


138


139







140
141
142

143
144

145






146
147
148
149
150








151
152







153




154
155



156







157
158
159
160
161






162
163
164

165
166



167
168
169
170
171


172







173
174
175

176
177

178






179
180
181
182
183








184
185





186
187



188
189
190
191


192









193


194




195
196
197

198
199

200





201
202
203


204


205





206
207
208





209
210

211






212
213
214
215
216










217
218
219
220
221
222
223
224







-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
+
+
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
-
+
+
+
-

-
+

-
-
-
+
+
+


-
-
+
+




-
+

-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+

-
-
-
-
-
-
-
-
+


-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
+


-
+

-
-
+

-
-
+
+

-
-
-
-
-
+
-
-
-
-
-
-
+
+
+
-
-
-
-
-
+

-
+
-
-
-
-
+
+
+
+

-
-
-
-
-
-
+


-
+

-
+
-
-
+
-
-
-
+
-
-
-
+
-
-
+
-
-
+
-
-
-
-
-
-
-
+


-
+

-
+
-
-
-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
+

-
-
-
-
-
-
-

-
-
-
-
+

-
-
-
+
-
-
-
-
-
-
-
+
+
+
+

-
-
-
-
-
-
+


-
+

-
-
-
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
+


-
+

-
+
-
-
-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
+

-
-
-
-
-
+
+
-
-
-
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
+


-
+

-
+
-
-
-
-
-
+
+
+
-
-
+
-
-
+
-
-
-
-
-
+


-
-
-
-
-
+

-
+
-
-
-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
-
-
+







@interface OFNumberSingleton: OFNumber
@end

static struct {
	Class isa;
} placeholder;

static OFNumberSingleton *zeroNumber, *oneNumber, *twoNumber;
static OFNumberSingleton *trueNumber, *falseNumber;

static void
initZeroNumber(void)
{
	zeroNumber = [[OFNumberSingleton alloc] initWithUnsignedChar: 0];
}

#define SINGLETON(var, sel, val)				\
	static OFNumberSingleton *var;				\
								\
	static void						\
	var##Init(void)						\
	{							\
		var = [[OFNumberSingleton alloc] sel val];	\
	}
SINGLETON(falseNumber, initWithBool:, false)
static void
initOneNumber(void)
SINGLETON(trueNumber, initWithBool:, true)
{
	oneNumber = [[OFNumberSingleton alloc] initWithUnsignedChar: 1];
SINGLETON(charZeroNumber, initWithChar:, 0)
}

SINGLETON(shortZeroNumber, initWithShort:, 0)
static void
initTwoNumber(void)
SINGLETON(intZeroNumber, initWithInt:, 0)
{
	twoNumber = [[OFNumberSingleton alloc] initWithUnsignedChar: 2];
SINGLETON(longZeroNumber, initWithLong:, 0)
SINGLETON(longLongZeroNumber, initWithLongLong:, 0)
SINGLETON(unsignedCharZeroNumber, initWithUnsignedChar:, 0)
}

SINGLETON(unsignedShortZeroNumber, initWithUnsignedShort:, 0)
static void
initTrueNumber(void)
SINGLETON(unsignedIntZeroNumber, initWithUnsignedInt:, 0)
{
	trueNumber = [[OFNumberSingleton alloc] initWithBool: true];
SINGLETON(unsignedLongZeroNumber, initWithUnsignedLong:, 0)
}

SINGLETON(unsignedLongLongZeroNumber, initWithUnsignedLongLong:, 0)
static void
initFalseNumber(void)
SINGLETON(floatZeroNumber, initWithFloat:, 0)
{
	falseNumber = [[OFNumberSingleton alloc] initWithBool: false];
}
SINGLETON(doubleZeroNumber, initWithDouble:, 0)
#undef SINGLETON


@implementation OFNumberPlaceholder
- (instancetype)initWithBool: (bool)bool_
- (instancetype)initWithBool: (bool)value
{
	if (bool_) {
		static of_once_t once;
		of_once(&once, initTrueNumber);
	if (value) {
		static of_once_t once = OF_ONCE_INIT;
		of_once(&once, trueNumberInit);
		return (id)trueNumber;
	} else {
		static of_once_t once;
		of_once(&once, initFalseNumber);
		static of_once_t once = OF_ONCE_INIT;
		of_once(&once, falseNumberInit);
		return (id)falseNumber;
	}
}

- (instancetype)initWithChar: (signed char)sChar
- (instancetype)initWithChar: (signed char)value
{
	if (sChar >= 0)
		return [self initWithUnsignedChar: sChar];

	if (value == 0) {
	return (id)[[OFNumber of_alloc] initWithChar: sChar];
}

		static of_once_t once = OF_ONCE_INIT;
- (instancetype)initWithShort: (short)sShort
{
	if (sShort >= 0)
		return [self initWithUnsignedShort: sShort];
	if (sShort >= SCHAR_MIN)
		return [self initWithChar: (signed char)sShort];

	return (id)[[OFNumber of_alloc] initWithShort: sShort];
}
		of_once(&once, charZeroNumberInit);
		return (id)charZeroNumber;
	}

- (instancetype)initWithInt: (int)sInt
{
	if (sInt >= 0)
		return [self initWithUnsignedInt: sInt];
	if (sInt >= SHRT_MIN)
		return [self initWithShort: (short)sInt];

	return (id)[[OFNumber of_alloc] initWithInt: sInt];
	return (id)[[OFNumber of_alloc] initWithChar: value];
}

- (instancetype)initWithLong: (long)sLong
{
	if (sLong >= 0)
		return [self initWithUnsignedLong: sLong];
	if (sLong >= INT_MIN)
		return [self initWithShort: (int)sLong];

	return (id)[[OFNumber of_alloc] initWithLong: sLong];
}
- (instancetype)initWithShort: (short)value
{
	if (value == 0) {
		static of_once_t once = OF_ONCE_INIT;
		of_once(&once, shortZeroNumberInit);
		return (id)shortZeroNumber;
	}

- (instancetype)initWithLongLong: (long long)sLongLong
{
	if (sLongLong >= 0)
		return [self initWithUnsignedLongLong: sLongLong];
	if (sLongLong >= LONG_MIN)
		return [self initWithLong: (long)sLongLong];

	return (id)[[OFNumber of_alloc] initWithLongLong: sLongLong];
	return (id)[[OFNumber of_alloc] initWithShort: value];
}

- (instancetype)initWithUnsignedChar: (unsigned char)uChar
- (instancetype)initWithInt: (int)value
{
	switch (uChar) {
	case 0: {
	if (value == 0) {
		static of_once_t once = OF_ONCE_INIT;
		of_once(&once, initZeroNumber);
		return (id)zeroNumber;
		of_once(&once, intZeroNumberInit);
		return (id)intZeroNumber;
	}
	case 1: {
		static of_once_t once = OF_ONCE_INIT;
		of_once(&once, initOneNumber);
		return (id)oneNumber;
	}

	case 2: {
		static of_once_t once = OF_ONCE_INIT;
		of_once(&once, initTwoNumber);
		return (id)twoNumber;
	}
	}
	return (id)[[OFNumber of_alloc] initWithInt: value];
}


	return (id)[[OFNumber of_alloc] initWithUnsignedChar: uChar];
}

- (instancetype)initWithUnsignedShort: (unsigned short)uShort
- (instancetype)initWithLong: (long)value
{
	if (uShort <= UCHAR_MAX)
	if (value == 0) {
		return [self initWithUnsignedChar: (unsigned char)uShort];

	return (id)[[OFNumber of_alloc] initWithUnsignedShort: uShort];
}
		static of_once_t once = OF_ONCE_INIT;
		of_once(&once, longZeroNumberInit);
		return (id)longZeroNumber;
	}

- (instancetype)initWithUnsignedInt: (unsigned int)uInt
{
	if (uInt <= USHRT_MAX)
		return [self initWithUnsignedShort: (unsigned short)uInt];

	return (id)[[OFNumber of_alloc] initWithUnsignedInt: uInt];
	return (id)[[OFNumber of_alloc] initWithLong: value];
}

- (instancetype)initWithUnsignedLong: (unsigned long)uLong
- (instancetype)initWithLongLong: (long long)value
{
	if (uLong <= UINT_MAX)
	if (value == 0) {
		return [self initWithUnsignedInt: (unsigned int)uLong];

		static of_once_t once = OF_ONCE_INIT;
	return (id)[[OFNumber of_alloc] initWithUnsignedLong: uLong];
}

		of_once(&once, longLongZeroNumberInit);
- (instancetype)initWithUnsignedLongLong: (unsigned long long)uLongLong
{
	if (uLongLong <= ULONG_MAX)
		return (id)longLongZeroNumber;
		return [self initWithUnsignedLong: (unsigned long)uLongLong];

	}
	return (id)[[OFNumber of_alloc] initWithUnsignedLongLong: uLongLong];
}


- (instancetype)initWithInt8: (int8_t)int8
{
	if (int8 >= 0)
		return [self initWithUInt8: int8];

	return (id)[[OFNumber of_alloc] initWithInt8: int8];
	return (id)[[OFNumber of_alloc] initWithLongLong: value];
}

- (instancetype)initWithInt16: (int16_t)int16
- (instancetype)initWithUnsignedChar: (unsigned char)value
{
	if (int16 >= 0)
	if (value == 0) {
		return [self initWithUInt16: int16];
	if (int16 >= INT8_MIN)
		return [self initWithInt8: (int8_t)int16];

	return (id)[[OFNumber of_alloc] initWithInt16: int16];
}
		static of_once_t once = OF_ONCE_INIT;
		of_once(&once, unsignedCharZeroNumberInit);
		return (id)unsignedCharZeroNumber;
	}

- (instancetype)initWithInt32: (int32_t)int32
{
	if (int32 >= 0)
		return [self initWithUInt32: int32];
	if (int32 >= INT16_MIN)
		return [self initWithInt16: (int16_t)int32];

	return (id)[[OFNumber of_alloc] initWithInt32: int32];
	return (id)[[OFNumber of_alloc] initWithUnsignedChar: value];
}

- (instancetype)initWithInt64: (int64_t)int64
{
	if (int64 >= 0)
		return [self initWithUInt64: int64];
	if (int64 >= INT32_MIN)
		return [self initWithInt32: (int32_t)int64];

	return (id)[[OFNumber of_alloc] initWithInt64: int64];
}

- (instancetype)initWithUInt8: (uint8_t)uInt8
- (instancetype)initWithUnsignedShort: (unsigned short)value
{
	return (id)[[OFNumber of_alloc] initWithUInt8: uInt8];
}

	if (value == 0) {
- (instancetype)initWithUInt16: (uint16_t)uInt16
{
	if (uInt16 <= UINT8_MAX)
		return [self initWithUInt8: (uint8_t)uInt16];

	return (id)[[OFNumber of_alloc] initWithUInt16: uInt16];
}
		static of_once_t once = OF_ONCE_INIT;
		of_once(&once, unsignedShortZeroNumberInit);
		return (id)unsignedShortZeroNumber;
	}

- (instancetype)initWithUInt32: (uint32_t)uInt32
{
	if (uInt32 <= UINT16_MAX)
		return [self initWithUInt16: (uint16_t)uInt32];

	return (id)[[OFNumber of_alloc] initWithUInt32: uInt32];
	return (id)[[OFNumber of_alloc] initWithUnsignedShort: value];
}

- (instancetype)initWithUInt64: (uint64_t)uInt64
- (instancetype)initWithUnsignedInt: (unsigned int)value
{
	if (uInt64 <= UINT32_MAX)
		return [self initWithUInt32: (uint32_t)uInt64];

	if (value == 0) {
		static of_once_t once = OF_ONCE_INIT;
		of_once(&once, unsignedIntZeroNumberInit);
		return (id)unsignedIntZeroNumber;
	}
	return (id)[[OFNumber of_alloc] initWithUInt64: uInt64];
}


- (instancetype)initWithSize: (size_t)size
{
	if (size <= ULONG_MAX)
		return [self initWithUnsignedLong: (unsigned long)size];

	return (id)[[OFNumber of_alloc] initWithSize: size];
	return (id)[[OFNumber of_alloc] initWithUnsignedInt: value];
}

- (instancetype)initWithSSize: (ssize_t)sSize
- (instancetype)initWithUnsignedLong: (unsigned long)value
{
	if (sSize >= 0)
	if (value == 0) {
		return [self initWithSize: sSize];
	if (sSize <= LONG_MIN)
		return [self initWithLong: (long)sSize];

	return (id)[[OFNumber of_alloc] initWithSSize: sSize];
}
		static of_once_t once = OF_ONCE_INIT;
		of_once(&once, unsignedLongZeroNumberInit);
		return (id)unsignedLongZeroNumber;
	}

- (instancetype)initWithIntMax: (intmax_t)intMax
{
	if (intMax >= 0)
		return [self initWithUIntMax: intMax];
	if (intMax <= LLONG_MIN)
		return [self initWithLongLong: (long long)intMax];

	return (id)[[OFNumber of_alloc] initWithIntMax: intMax];
	return (id)[[OFNumber of_alloc] initWithUnsignedLong: value];
}

- (instancetype)initWithUIntMax: (uintmax_t)uIntMax
{
	if (uIntMax <= ULLONG_MAX)
		return [self initWithUnsignedLongLong:

- (instancetype)initWithUnsignedLongLong: (unsigned long long)value
		    (unsigned long long)uIntMax];

	return (id)[[OFNumber of_alloc] initWithUIntMax: uIntMax];
{
	if (value == 0) {
		static of_once_t once = OF_ONCE_INIT;
		of_once(&once, unsignedLongLongZeroNumberInit);
}

		return (id)unsignedLongLongZeroNumber;
#ifdef __clang__
/*
 * This warning should probably not exist at all, as it prevents checking
 * whether one type fits into another in a portable way.
 */
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
#endif

	}
- (instancetype)initWithPtrDiff: (ptrdiff_t)ptrDiff
{

	if (ptrDiff >= LLONG_MIN && ptrDiff <= LLONG_MAX)
		return [self initWithLongLong: (long long)ptrDiff];

	return (id)[[OFNumber of_alloc] initWithPtrDiff: ptrDiff];
	return (id)[[OFNumber of_alloc] initWithUnsignedLongLong: value];
}

- (instancetype)initWithIntPtr: (intptr_t)intPtr
- (instancetype)initWithFloat: (float)value
{
	if (intPtr >= 0)
	if (value == 0) {
		return [self initWithUIntPtr: intPtr];
	if (intPtr >= LLONG_MIN)
		return [self initWithLongLong: (long long)intPtr];

	return (id)[[OFNumber of_alloc] initWithIntPtr: intPtr];
		static of_once_t once = OF_ONCE_INIT;
		of_once(&once, floatZeroNumberInit);
		return (id)floatZeroNumber;
}

	}
- (instancetype)initWithUIntPtr: (uintptr_t)uIntPtr
{

	if (uIntPtr <= ULLONG_MAX)
		return [self initWithUnsignedLongLong:
		    (unsigned long long)uIntPtr];

	return (id)[[OFNumber of_alloc] initWithUIntPtr: uIntPtr];
	return (id)[[OFNumber of_alloc] initWithFloat: value];
}

#ifdef __clang__
# pragma clang diagnostic pop
#endif

- (instancetype)initWithFloat: (float)float_
- (instancetype)initWithDouble: (double)value
{
	if (float_ == (uintmax_t)float_)
	if (value == 0) {
		return [self initWithUIntMax: (uintmax_t)float_];
	if (float_ == (intmax_t)float_)
		return [self initWithIntMax: (intmax_t)float_];

	return (id)[[OFNumber of_alloc] initWithFloat: float_];
}
		static of_once_t once = OF_ONCE_INIT;
		of_once(&once, doubleZeroNumberInit);
		return (id)doubleZeroNumber;
	}

- (instancetype)initWithDouble: (double)double_
{
	if (double_ == (uintmax_t)double_)
		return [self initWithUIntMax: (uintmax_t)double_];
	if (double_ == (intmax_t)double_)
		return [self initWithIntMax: (intmax_t)double_];
	if (double_ == (float)double_)
		return [self initWithFloat: (float)double_];

	return (id)[[OFNumber of_alloc] initWithDouble: double_];
	return (id)[[OFNumber of_alloc] initWithDouble: value];
}

- (instancetype)initWithSerialization: (OFXMLElement *)element
{
	return (id)[[OFNumber of_alloc] initWithSerialization: element];
}
@end
406
407
408
409
410
411
412
413

414
415

416
417
418

419
420

421
422
423

424
425

426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453

454
455

456
457
458
459
460
461
462
463
464
465
466
467
468

469
470

471
472
473

474
475

476
477
478

479
480
481
482

483
484
485

486
487
488

489
490

491
492
493

494
495

496
497
498
499
500
501
502
503
504
505
506
507
508

509
510

511
512
513
514
515
516
517
518

519
520
521
522
523
524
525

526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543

544
545

546
547
548

549
550

551
552
553
554
555
556
557
558

559
560
561
562

563
564
565
566
567
568
569

570
571
572
573

574
575
576
577
578
579
580

581
582
583
584

585
586
587
588
589
590
591

592
593
594
595

596
597
598
599
600
601
602

603
604
605
606

607
608
609
610
611
612
613

614
615
616
617

618
619
620
621
622
623
624

625
626
627
628

629
630
631
632
633
634
635

636
637
638
639

640
641
642
643
644
645
646

647
648
649
650

651
652
653
654
655
656
657

658
659
660
661

662
663
664
665
666
667
668

669
670
671
672

673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811

812
813
814
815

816
817
818
819
820
821
822

823
824
825
826

827
828
829
830
831
832
833

834
835
836
837

838
839
840
841
842
843
844

845
846
847
848

849
850
851
852
853
854
855

856
857
858
859

860
861
862
863
864
865
866
260
261
262
263
264
265
266

267
268

269
270
271

272
273

274
275
276

277
278

279
280




















281






282
283

284
285
286











287
288

289
290
291

292
293

294
295
296

297




298



299
300
301

302
303

304
305
306

307
308

309
310
311











312
313

314





315
316

317
318






319
320
321
















322
323

324
325
326

327
328

329
330
331
332
333
334
335
336

337
338
339
340

341
342
343
344
345
346
347

348
349
350
351

352
353
354
355
356
357
358

359
360
361
362

363
364
365
366
367
368
369

370
371
372
373

374
375
376
377
378
379
380

381
382
383
384

385
386
387
388
389
390
391

392
393
394
395

396
397
398
399
400
401
402

403
404
405
406

407
408
409
410
411
412
413

414
415
416
417

418
419
420
421
422
423
424

425
426
427
428

429
430
431
432
433
434
435

436
437
438
439

440
441
442
443
444
445
446

447
448
449
450

451
452
453
454
455
456
457





































































































































458
459
460
461

462
463
464
465
466
467
468

469
470
471
472

473
474
475
476
477
478
479

480
481
482
483

484
485
486
487
488
489
490

491
492
493
494

495
496
497
498
499
500
501

502
503
504
505

506
507
508
509
510
511
512
513







-
+

-
+


-
+

-
+


-
+

-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
+

-
+


-
-
-
-
-
-
-
-
-
-
-
+

-
+


-
+

-
+


-
+
-
-
-
-
+
-
-
-
+


-
+

-
+


-
+

-
+


-
-
-
-
-
-
-
-
-
-
-
+

-
+
-
-
-
-
-


-
+

-
-
-
-
-
-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

-
+


-
+

-
+







-
+



-
+






-
+



-
+






-
+



-
+






-
+



-
+






-
+



-
+






-
+



-
+






-
+



-
+






-
+



-
+






-
+



-
+






-
+



-
+






-
+



-
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+



-
+






-
+



-
+






-
+



-
+






-
+



-
+






-
+



-
+







{
	if (self == [OFNumber class])
		return (id)&placeholder;

	return [super alloc];
}

+ (instancetype)numberWithBool: (bool)bool_
+ (instancetype)numberWithBool: (bool)value
{
	return [[[self alloc] initWithBool: bool_] autorelease];
	return [[[self alloc] initWithBool: value] autorelease];
}

+ (instancetype)numberWithChar: (signed char)sChar
+ (instancetype)numberWithChar: (signed char)value
{
	return [[[self alloc] initWithChar: sChar] autorelease];
	return [[[self alloc] initWithChar: value] autorelease];
}

+ (instancetype)numberWithShort: (short)sShort
+ (instancetype)numberWithShort: (short)value
{
	return [[[self alloc] initWithShort: sShort] autorelease];
	return [[[self alloc] initWithShort: value] autorelease];
}

+ (instancetype)numberWithInt: (int)sInt
{
	return [[[self alloc] initWithInt: sInt] autorelease];
}

+ (instancetype)numberWithLong: (long)sLong
{
	return [[[self alloc] initWithLong: sLong] autorelease];
}

+ (instancetype)numberWithLongLong: (long long)sLongLong
{
	return [[[self alloc] initWithLongLong: sLongLong] autorelease];
}

+ (instancetype)numberWithUnsignedChar: (unsigned char)uChar
{
	return [[[self alloc] initWithUnsignedChar: uChar] autorelease];
}

+ (instancetype)numberWithUnsignedShort: (unsigned short)uShort
{
	return [[[self alloc] initWithUnsignedShort: uShort] autorelease];
}

+ (instancetype)numberWithUnsignedInt: (unsigned int)uInt
+ (instancetype)numberWithInt: (int)value
{
	return [[[self alloc] initWithUnsignedInt: uInt] autorelease];
	return [[[self alloc] initWithInt: value] autorelease];
}

+ (instancetype)numberWithUnsignedLong: (unsigned long)uLong
{
	return [[[self alloc] initWithUnsignedLong: uLong] autorelease];
}

+ (instancetype)numberWithUnsignedLongLong: (unsigned long long)uLongLong
{
	return [[[self alloc] initWithUnsignedLongLong: uLongLong] autorelease];
}

+ (instancetype)numberWithInt8: (int8_t)int8
+ (instancetype)numberWithLong: (long)value
{
	return [[[self alloc] initWithInt8: int8] autorelease];
	return [[[self alloc] initWithLong: value] autorelease];
}

+ (instancetype)numberWithInt16: (int16_t)int16
+ (instancetype)numberWithLongLong: (long long)value
{
	return [[[self alloc] initWithInt16: int16] autorelease];
	return [[[self alloc] initWithLongLong: value] autorelease];
}

+ (instancetype)numberWithInt32: (int32_t)int32
+ (instancetype)numberWithUnsignedChar: (unsigned char)value
{
	return [[[self alloc] initWithInt32: int32] autorelease];
}

{
+ (instancetype)numberWithInt64: (int64_t)int64
{
	return [[[self alloc] initWithInt64: int64] autorelease];
	return [[[self alloc] initWithUnsignedChar: value] autorelease];
}

+ (instancetype)numberWithUInt8: (uint8_t)uInt8
+ (instancetype)numberWithUnsignedShort: (unsigned short)value
{
	return [[[self alloc] initWithUInt8: uInt8] autorelease];
	return [[[self alloc] initWithUnsignedShort: value] autorelease];
}

+ (instancetype)numberWithUInt16: (uint16_t)uInt16
+ (instancetype)numberWithUnsignedInt: (unsigned int)value
{
	return [[[self alloc] initWithUInt16: uInt16] autorelease];
	return [[[self alloc] initWithUnsignedInt: value] autorelease];
}

+ (instancetype)numberWithUInt32: (uint32_t)uInt32
{
	return [[[self alloc] initWithUInt32: uInt32] autorelease];
}

+ (instancetype)numberWithUInt64: (uint64_t)uInt64
{
	return [[[self alloc] initWithUInt64: uInt64] autorelease];
}

+ (instancetype)numberWithSize: (size_t)size
+ (instancetype)numberWithUnsignedLong: (unsigned long)value
{
	return [[[self alloc] initWithSize: size] autorelease];
	return [[[self alloc] initWithUnsignedLong: value] autorelease];
}

+ (instancetype)numberWithSSize: (ssize_t)sSize
{
	return [[[self alloc] initWithSSize: sSize] autorelease];
}

+ (instancetype)numberWithIntMax: (intmax_t)intMax
+ (instancetype)numberWithUnsignedLongLong: (unsigned long long)value
{
	return [[[self alloc] initWithIntMax: intMax] autorelease];
}

+ (instancetype)numberWithUIntMax: (uintmax_t)uIntMax
{
	return [[[self alloc] initWithUIntMax: uIntMax] autorelease];
	return [[[self alloc] initWithUnsignedLongLong: value] autorelease];
}

+ (instancetype)numberWithPtrDiff: (ptrdiff_t)ptrDiff
{
	return [[[self alloc] initWithPtrDiff: ptrDiff] autorelease];
}

+ (instancetype)numberWithIntPtr: (intptr_t)intPtr
{
	return [[[self alloc] initWithIntPtr: intPtr] autorelease];
}

+ (instancetype)numberWithUIntPtr: (uintptr_t)uIntPtr
{
	return [[[self alloc] initWithUIntPtr: uIntPtr] autorelease];
}

+ (instancetype)numberWithFloat: (float)float_
+ (instancetype)numberWithFloat: (float)value
{
	return [[[self alloc] initWithFloat: float_] autorelease];
	return [[[self alloc] initWithFloat: value] autorelease];
}

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

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithBool: (bool)bool_
- (instancetype)initWithBool: (bool)value
{
	self = [super init];

	_value.unsigned_ = bool_;
	_value.unsigned_ = value;
	_type = OF_NUMBER_TYPE_UNSIGNED;
	_typeEncoding = @encode(bool);

	return self;
}

- (instancetype)initWithChar: (signed char)sChar
- (instancetype)initWithChar: (signed char)value
{
	self = [super init];

	_value.signed_ = sChar;
	_value.signed_ = value;
	_type = OF_NUMBER_TYPE_SIGNED;
	_typeEncoding = @encode(signed char);

	return self;
}

- (instancetype)initWithShort: (short)sShort
- (instancetype)initWithShort: (short)value
{
	self = [super init];

	_value.signed_ = sShort;
	_value.signed_ = value;
	_type = OF_NUMBER_TYPE_SIGNED;
	_typeEncoding = @encode(short);

	return self;
}

- (instancetype)initWithInt: (int)sInt
- (instancetype)initWithInt: (int)value
{
	self = [super init];

	_value.signed_ = sInt;
	_value.signed_ = value;
	_type = OF_NUMBER_TYPE_SIGNED;
	_typeEncoding = @encode(int);

	return self;
}

- (instancetype)initWithLong: (long)sLong
- (instancetype)initWithLong: (long)value
{
	self = [super init];

	_value.signed_ = sLong;
	_value.signed_ = value;
	_type = OF_NUMBER_TYPE_SIGNED;
	_typeEncoding = @encode(long);

	return self;
}

- (instancetype)initWithLongLong: (long long)sLongLong
- (instancetype)initWithLongLong: (long long)value
{
	self = [super init];

	_value.signed_ = sLongLong;
	_value.signed_ = value;
	_type = OF_NUMBER_TYPE_SIGNED;
	_typeEncoding = @encode(long long);

	return self;
}

- (instancetype)initWithUnsignedChar: (unsigned char)uChar
- (instancetype)initWithUnsignedChar: (unsigned char)value
{
	self = [super init];

	_value.unsigned_ = uChar;
	_value.unsigned_ = value;
	_type = OF_NUMBER_TYPE_UNSIGNED;
	_typeEncoding = @encode(unsigned long);

	return self;
}

- (instancetype)initWithUnsignedShort: (unsigned short)uShort
- (instancetype)initWithUnsignedShort: (unsigned short)value
{
	self = [super init];

	_value.unsigned_ = uShort;
	_value.unsigned_ = value;
	_type = OF_NUMBER_TYPE_UNSIGNED;
	_typeEncoding = @encode(unsigned short);

	return self;
}

- (instancetype)initWithUnsignedInt: (unsigned int)uInt
- (instancetype)initWithUnsignedInt: (unsigned int)value
{
	self = [super init];

	_value.unsigned_ = uInt;
	_value.unsigned_ = value;
	_type = OF_NUMBER_TYPE_UNSIGNED;
	_typeEncoding = @encode(unsigned int);

	return self;
}

- (instancetype)initWithUnsignedLong: (unsigned long)uLong
- (instancetype)initWithUnsignedLong: (unsigned long)value
{
	self = [super init];

	_value.unsigned_ = uLong;
	_value.unsigned_ = value;
	_type = OF_NUMBER_TYPE_UNSIGNED;
	_typeEncoding = @encode(unsigned long);

	return self;
}

- (instancetype)initWithUnsignedLongLong: (unsigned long long)uLongLong
- (instancetype)initWithUnsignedLongLong: (unsigned long long)value
{
	self = [super init];

	_value.unsigned_ = uLongLong;
	_value.unsigned_ = value;
	_type = OF_NUMBER_TYPE_UNSIGNED;
	_typeEncoding = @encode(unsigned long long);

	return self;
}

- (instancetype)initWithInt8: (int8_t)int8
{
	self = [super init];

	_value.signed_ = int8;
	_type = OF_NUMBER_TYPE_SIGNED;
	_typeEncoding = @encode(int8_t);

	return self;
}

- (instancetype)initWithInt16: (int16_t)int16
{
	self = [super init];

	_value.signed_ = int16;
	_type = OF_NUMBER_TYPE_SIGNED;
	_typeEncoding = @encode(int16_t);

	return self;
}

- (instancetype)initWithInt32: (int32_t)int32
{
	self = [super init];

	_value.signed_ = int32;
	_type = OF_NUMBER_TYPE_SIGNED;
	_typeEncoding = @encode(int32_t);

	return self;
}

- (instancetype)initWithInt64: (int64_t)int64
{
	self = [super init];

	_value.signed_ = int64;
	_type = OF_NUMBER_TYPE_SIGNED;
	_typeEncoding = @encode(int64_t);

	return self;
}

- (instancetype)initWithUInt8: (uint8_t)uInt8
{
	self = [super init];

	_value.unsigned_ = uInt8;
	_type = OF_NUMBER_TYPE_UNSIGNED;
	_typeEncoding = @encode(uint8_t);

	return self;
}

- (instancetype)initWithUInt16: (uint16_t)uInt16
{
	self = [super init];

	_value.unsigned_ = uInt16;
	_type = OF_NUMBER_TYPE_UNSIGNED;
	_typeEncoding = @encode(uint16_t);

	return self;
}

- (instancetype)initWithUInt32: (uint32_t)uInt32
{
	self = [super init];

	_value.unsigned_ = uInt32;
	_type = OF_NUMBER_TYPE_UNSIGNED;
	_typeEncoding = @encode(uint32_t);

	return self;
}

- (instancetype)initWithUInt64: (uint64_t)uInt64
{
	self = [super init];

	_value.unsigned_ = uInt64;
	_type = OF_NUMBER_TYPE_UNSIGNED;
	_typeEncoding = @encode(uint64_t);

	return self;
}

- (instancetype)initWithSize: (size_t)size
{
	self = [super init];

	_value.unsigned_ = size;
	_type = OF_NUMBER_TYPE_UNSIGNED;
	_typeEncoding = @encode(size_t);

	return self;
}

- (instancetype)initWithSSize: (ssize_t)sSize
{
	self = [super init];

	_value.signed_ = sSize;
	_type = OF_NUMBER_TYPE_SIGNED;
	_typeEncoding = @encode(ssize_t);

	return self;
}

- (instancetype)initWithIntMax: (intmax_t)intMax
{
	self = [super init];

	_value.signed_ = intMax;
	_type = OF_NUMBER_TYPE_SIGNED;
	_typeEncoding = @encode(intmax_t);

	return self;
}

- (instancetype)initWithUIntMax: (uintmax_t)uIntMax
{
	self = [super init];

	_value.unsigned_ = uIntMax;
	_type = OF_NUMBER_TYPE_UNSIGNED;
	_typeEncoding = @encode(uintmax_t);

	return self;
}

- (instancetype)initWithPtrDiff: (ptrdiff_t)ptrDiff
- (instancetype)initWithPtrDiff: (ptrdiff_t)value
{
	self = [super init];

	_value.signed_ = ptrDiff;
	_value.signed_ = value;
	_type = OF_NUMBER_TYPE_SIGNED;
	_typeEncoding = @encode(ptrdiff_t);

	return self;
}

- (instancetype)initWithIntPtr: (intptr_t)intPtr
- (instancetype)initWithIntPtr: (intptr_t)value
{
	self = [super init];

	_value.signed_ = intPtr;
	_value.signed_ = value;
	_type = OF_NUMBER_TYPE_SIGNED;
	_typeEncoding = @encode(intptr_t);

	return self;
}

- (instancetype)initWithUIntPtr: (uintptr_t)uIntPtr
- (instancetype)initWithUIntPtr: (uintptr_t)value
{
	self = [super init];

	_value.unsigned_ = uIntPtr;
	_value.unsigned_ = value;
	_type = OF_NUMBER_TYPE_UNSIGNED;
	_typeEncoding = @encode(uintptr_t);

	return self;
}

- (instancetype)initWithFloat: (float)float_
- (instancetype)initWithFloat: (float)value
{
	self = [super init];

	_value.float_ = float_;
	_value.float_ = value;
	_type = OF_NUMBER_TYPE_FLOAT;
	_typeEncoding = @encode(float);

	return self;
}

- (instancetype)initWithDouble: (double)double_
- (instancetype)initWithDouble: (double)value
{
	self = [super init];

	_value.float_ = double_;
	_value.float_ = value;
	_type = OF_NUMBER_TYPE_FLOAT;
	_typeEncoding = @encode(double);

	return self;
}

- (instancetype)initWithSerialization: (OFXMLElement *)element
881
882
883
884
885
886
887
888







889
890

891
892
893


894
895
896
897
898
899


900
901
902
903
904
905
906
528
529
530
531
532
533
534

535
536
537
538
539
540
541
542

543



544
545
546





547
548
549
550
551
552
553
554
555







-
+
+
+
+
+
+
+

-
+
-
-
-
+
+

-
-
-
-
-
+
+







			OFString *stringValue = element.stringValue;
			if ([stringValue isEqual: @"true"])
				self = [self initWithBool: true];
			else if ([stringValue isEqual: @"false"])
				self = [self initWithBool: false];
			else
				@throw [OFInvalidArgumentException exception];
		} else if ([typeString isEqual: @"float"])
		} else if ([typeString isEqual: @"float"]) {
			unsigned long long value =
			    [element unsignedLongLongValueWithBase: 16];

			if (value > UINT64_MAX)
				@throw [OFOutOfRangeException exception];

			self = [self initWithDouble: OF_BSWAP_DOUBLE_IF_LE(
			    OF_INT_TO_DOUBLE_RAW(OF_BSWAP64_IF_LE(
			    OF_INT_TO_DOUBLE_RAW(OF_BSWAP64_IF_LE(value)))];
			    (uint64_t)element.hexadecimalValue)))];
		else if ([typeString isEqual: @"signed"])
			self = [self initWithIntMax: element.doubleValue];
		} else if ([typeString isEqual: @"signed"])
			self = [self initWithLongLong: element.longLongValue];
		else if ([typeString isEqual: @"unsigned"])
			/*
			 * FIXME: This will fail if the value is bigger than
			 *	  INTMAX_MAX!
			 */
			self = [self initWithUIntMax: element.decimalValue];
			self = [self initWithUnsignedLongLong:
			    element.unsignedLongLongValue];
		else
			@throw [OFInvalidArgumentException exception];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
658
659
660
661
662
663
664











































































665
666
667
668
669
670
671







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







}

- (unsigned long long)unsignedLongLongValue
{
	RETURN_AS(unsigned long long)
}

- (int8_t)int8Value
{
	RETURN_AS(int8_t)
}

- (int16_t)int16Value
{
	RETURN_AS(int16_t)
}

- (int32_t)int32Value
{
	RETURN_AS(int32_t)
}

- (int64_t)int64Value
{
	RETURN_AS(int64_t)
}

- (uint8_t)uInt8Value
{
	RETURN_AS(uint8_t)
}

- (uint16_t)uInt16Value
{
	RETURN_AS(uint16_t)
}

- (uint32_t)uInt32Value
{
	RETURN_AS(uint32_t)
}

- (uint64_t)uInt64Value
{
	RETURN_AS(uint64_t)
}

- (size_t)sizeValue
{
	RETURN_AS(size_t)
}

- (ssize_t)sSizeValue
{
	RETURN_AS(ssize_t)
}

- (intmax_t)intMaxValue
{
	RETURN_AS(intmax_t)
}

- (uintmax_t)uIntMaxValue
{
	RETURN_AS(uintmax_t)
}

- (ptrdiff_t)ptrDiffValue
{
	RETURN_AS(ptrdiff_t)
}

- (intptr_t)intPtrValue
{
	RETURN_AS(intptr_t)
}

- (uintptr_t)uIntPtrValue
{
	RETURN_AS(uintptr_t)
}

- (float)floatValue
{
	RETURN_AS(float)
}

- (double)doubleValue
{
1122
1123
1124
1125
1126
1127
1128
1129

1130
1131

1132
1133
1134
1135
1136
1137
1138
696
697
698
699
700
701
702

703
704

705
706
707
708
709
710
711
712







-
+

-
+







			return false;

		return (value1 == value2);
	}

	if (_type == OF_NUMBER_TYPE_SIGNED ||
	    number->_type == OF_NUMBER_TYPE_SIGNED)
		return (number.intMaxValue == self.intMaxValue);
		return (number.longLongValue == self.longLongValue);

	return (number.uIntMaxValue == self.uIntMaxValue);
	return (number.unsignedLongLongValue == self.unsignedLongLongValue);
}

- (of_comparison_result_t)compare: (id <OFComparing>)object
{
	OFNumber *number;

	if (![(id)object isKindOfClass: [OFNumber class]])
1149
1150
1151
1152
1153
1154
1155
1156
1157


1158
1159
1160
1161
1162
1163
1164
1165
1166
1167


1168
1169
1170
1171
1172
1173
1174
723
724
725
726
727
728
729


730
731
732
733
734
735
736
737
738
739


740
741
742
743
744
745
746
747
748







-
-
+
+








-
-
+
+







			return OF_ORDERED_DESCENDING;
		if (double1 < double2)
			return OF_ORDERED_ASCENDING;

		return OF_ORDERED_SAME;
	} else if (_type == OF_NUMBER_TYPE_SIGNED ||
	    number->_type == OF_NUMBER_TYPE_SIGNED) {
		intmax_t int1 = self.intMaxValue;
		intmax_t int2 = number.intMaxValue;
		long long int1 = self.longLongValue;
		long long int2 = number.longLongValue;

		if (int1 > int2)
			return OF_ORDERED_DESCENDING;
		if (int1 < int2)
			return OF_ORDERED_ASCENDING;

		return OF_ORDERED_SAME;
	} else {
		uintmax_t uint1 = self.uIntMaxValue;
		uintmax_t uint2 = number.uIntMaxValue;
		unsigned long long uint1 = self.unsignedLongLongValue;
		unsigned long long uint2 = number.unsignedLongLongValue;

		if (uint1 > uint2)
			return OF_ORDERED_DESCENDING;
		if (uint1 < uint2)
			return OF_ORDERED_ASCENDING;

		return OF_ORDERED_SAME;
1188
1189
1190
1191
1192
1193
1194
1195

1196
1197
1198
1199
1200
1201
1202
1203
1204
1205


1206
1207
1208
1209



1210
1211
1212
1213
1214
1215
1216
762
763
764
765
766
767
768

769










770
771
772



773
774
775
776
777
778
779
780
781
782







-
+
-
-
-
-
-
-
-
-
-
-
+
+

-
-
-
+
+
+







		if (isnan(self.doubleValue))
			return 0;

		d = OF_BSWAP_DOUBLE_IF_BE(self.doubleValue);

		for (uint_fast8_t i = 0; i < sizeof(double); i++)
			OF_HASH_ADD(hash, ((char *)&d)[i]);
	} else if (type == OF_NUMBER_TYPE_SIGNED) {
	} else if (type == OF_NUMBER_TYPE_SIGNED ||
		intmax_t v = self.intMaxValue * -1;

		while (v != 0) {
			OF_HASH_ADD(hash, v & 0xFF);
			v >>= 8;
		}

		OF_HASH_ADD(hash, 1);
	} else if (type == OF_NUMBER_TYPE_UNSIGNED) {
		uintmax_t v = self.uIntMaxValue;
	    type == OF_NUMBER_TYPE_UNSIGNED) {
		unsigned long long value = self.unsignedLongLongValue;

		while (v != 0) {
			OF_HASH_ADD(hash, v & 0xFF);
			v >>= 8;
		while (value != 0) {
			OF_HASH_ADD(hash, value & 0xFF);
			value >>= 8;
		}
	} else
		@throw [OFInvalidFormatException exception];

	OF_HASH_FINALIZE(hash);

	return hash;
1229
1230
1231
1232
1233
1234
1235
1236

1237
1238

1239
1240
1241
1242
1243
1244
1245
795
796
797
798
799
800
801

802
803

804
805
806
807
808
809
810
811







-
+

-
+







- (OFString *)stringValue
{
	if (*_typeEncoding == 'B')
		return (_value.unsigned_ ? @"true" : @"false");
	if (_type == OF_NUMBER_TYPE_FLOAT)
		return [OFString stringWithFormat: @"%g", _value.float_];
	if (_type == OF_NUMBER_TYPE_SIGNED)
		return [OFString stringWithFormat: @"%jd", _value.signed_];
		return [OFString stringWithFormat: @"%lld", _value.signed_];
	if (_type == OF_NUMBER_TYPE_UNSIGNED)
		return [OFString stringWithFormat: @"%ju", _value.unsigned_];
		return [OFString stringWithFormat: @"%llu", _value.unsigned_];

	@throw [OFInvalidFormatException exception];
}

- (OFXMLElement *)XMLElementBySerializing
{
	void *pool = objc_autoreleasePoolPush();
1335
1336
1337
1338
1339
1340
1341
1342

1343
1344
1345
1346
1347
1348
1349
901
902
903
904
905
906
907

908
909
910
911
912
913
914
915







-
+







		data = [OFMutableData dataWithItemSize: 1
					      capacity: 9];

		[data addItem: &type];
		[data addItems: &tmp
			 count: sizeof(tmp)];
	} else if (_type == OF_NUMBER_TYPE_SIGNED) {
		intmax_t value = self.intMaxValue;
		long long value = self.longLongValue;

		if (value >= -32 && value < 0) {
			uint8_t tmp = 0xE0 | ((uint8_t)(value - 32) & 0x1F);

			data = [OFMutableData dataWithItems: &tmp
						      count: 1];
		} else if (value >= INT8_MIN && value <= INT8_MAX) {
1384
1385
1386
1387
1388
1389
1390
1391

1392
1393
1394
1395
1396
1397
1398
950
951
952
953
954
955
956

957
958
959
960
961
962
963
964







-
+








			[data addItem: &type];
			[data addItems: &tmp
				 count: sizeof(tmp)];
		} else
			@throw [OFOutOfRangeException exception];
	} else if (_type == OF_NUMBER_TYPE_UNSIGNED) {
		uintmax_t value = self.uIntMaxValue;
		unsigned long long value = self.unsignedLongLongValue;

		if (value <= 127) {
			uint8_t tmp = ((uint8_t)value & 0x7F);

			data = [OFMutableData dataWithItems: &tmp
						      count: 1];
		} else if (value <= UINT8_MAX) {