ObjFW  Check-in [e4344e3c5e]

Overview
Comment:OFNumber API improvement.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e4344e3c5e8eae201951a9e1618566ca9324a4c913033009b33dc1d8f62af0df
User & Date: js on 2010-04-30 13:07:56
Other Links: manifest | tags
Context
2010-04-30
13:59
Documentation improvement (replaced "an uint*" with "a uint*"). check-in: e259d77a62 user: js tags: trunk
13:07
OFNumber API improvement. check-in: e4344e3c5e user: js tags: trunk
12:56
We can't use isUTF8 here as it might be an OFConstString. check-in: 0166740a39 user: js tags: trunk
Changes

Modified src/OFNumber.h from [bdf451cad0] to [ec96a4eaff].

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
 */
- (double)doubleValue;

/**
 * \param num The OFNumber to add
 * \return A new autoreleased OFNumber added with the specified OFNumber
 */
- (OFNumber*)numberByAdding: (OFNumber*)num;

/**
 * \param num The OFNumber to substract
 * \return A new autoreleased OFNumber subtracted by the specified OFNumber
 */
- (OFNumber*)numberBySubtracting: (OFNumber*)num;

/**
 * \param num The OFNumber to multiply with
 * \return A new autoreleased OFNumber multiplied with the specified OFNumber
 */
- (OFNumber*)numberByMultiplyingWith: (OFNumber*)num;

/**
 * \param num The OFNumber to divide by
 * \return A new autoreleased OFNumber devided by the specified OFNumber
 */
- (OFNumber*)numberByDividingBy: (OFNumber*)num;

/**
 * ANDs two OFNumbers, returning a new one.
 *
 * Does not work with floating point types!
 *
 * \param num The number to AND with.
 * \return A new autoreleased OFNumber ANDed with the specified OFNumber
 */
- (OFNumber*)numberByANDing: (OFNumber*)num;

/**
 * ORs two OFNumbers, returning a new one.
 *
 * Does not work with floating point types!
 *
 * \param num The number to OR with.
 * \return A new autoreleased OFNumber ORed with the specified OFNumber
 */
- (OFNumber*)numberByORing: (OFNumber*)num;

/**
 * XORs two OFNumbers, returning a new one.
 *
 * Does not work with floating point types!
 *
 * \param num The number to XOR with.
 * \return A new autoreleased OFNumber XORed with the specified OFNumber
 */
- (OFNumber*)numberByXORing: (OFNumber*)num;

/**
 * Bitshifts the OFNumber to the left by the specified OFNumber, returning a new
 * one.
 *
 * Does not work with floating point types!
 *
 * \param num The number of bits to shift to the left
 * \return A new autoreleased OFNumber bitshifted to the left with the
 *	   specified OFNumber
 */
- (OFNumber*)numberByShiftingLeftBy: (OFNumber*)num;

/**
 * Bitshifts the OFNumber to the right by the specified OFNumber, returning a
 * new one.
 *
 * Does not work with floating point types!
 *
 * \param num The number of bits to shift to the right
 * \return A new autoreleased OFNumber bitshifted to the right with the
 *	   specified OFNumber
 */
- (OFNumber*)numberByShiftingRightBy: (OFNumber*)num;

/**
 * \return A new autoreleased OFNumber with the value increased by one.
 */
- (OFNumber*)numberByIncreasing;

/**
 * \return A new autoreleased OFNumber with the value decreased by one.
 */
- (OFNumber*)numberByDecreasing;
@end







|





|





|





|









|









|









|











|











|











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
 */
- (double)doubleValue;

/**
 * \param num The OFNumber to add
 * \return A new autoreleased OFNumber added with the specified OFNumber
 */
- (OFNumber*)numberByAddingNumber: (OFNumber*)num;

/**
 * \param num The OFNumber to substract
 * \return A new autoreleased OFNumber subtracted by the specified OFNumber
 */
- (OFNumber*)numberBySubtractingNumber: (OFNumber*)num;

/**
 * \param num The OFNumber to multiply with
 * \return A new autoreleased OFNumber multiplied with the specified OFNumber
 */
- (OFNumber*)numberByMultiplyingWithNumber: (OFNumber*)num;

/**
 * \param num The OFNumber to divide by
 * \return A new autoreleased OFNumber devided by the specified OFNumber
 */
- (OFNumber*)numberByDividingWithNumber: (OFNumber*)num;

/**
 * ANDs two OFNumbers, returning a new one.
 *
 * Does not work with floating point types!
 *
 * \param num The number to AND with.
 * \return A new autoreleased OFNumber ANDed with the specified OFNumber
 */
- (OFNumber*)numberByANDingWithNumber: (OFNumber*)num;

/**
 * ORs two OFNumbers, returning a new one.
 *
 * Does not work with floating point types!
 *
 * \param num The number to OR with.
 * \return A new autoreleased OFNumber ORed with the specified OFNumber
 */
- (OFNumber*)numberByORingWithNumber: (OFNumber*)num;

/**
 * XORs two OFNumbers, returning a new one.
 *
 * Does not work with floating point types!
 *
 * \param num The number to XOR with.
 * \return A new autoreleased OFNumber XORed with the specified OFNumber
 */
- (OFNumber*)numberByXORingWithNumber: (OFNumber*)num;

/**
 * Bitshifts the OFNumber to the left by the specified OFNumber, returning a new
 * one.
 *
 * Does not work with floating point types!
 *
 * \param num The number of bits to shift to the left
 * \return A new autoreleased OFNumber bitshifted to the left with the
 *	   specified OFNumber
 */
- (OFNumber*)numberByShiftingLeftWithNumber: (OFNumber*)num;

/**
 * Bitshifts the OFNumber to the right by the specified OFNumber, returning a
 * new one.
 *
 * Does not work with floating point types!
 *
 * \param num The number of bits to shift to the right
 * \return A new autoreleased OFNumber bitshifted to the right with the
 *	   specified OFNumber
 */
- (OFNumber*)numberByShiftingRightWithNumber: (OFNumber*)num;

/**
 * \return A new autoreleased OFNumber with the value increased by one.
 */
- (OFNumber*)numberByIncreasing;

/**
 * \return A new autoreleased OFNumber with the value decreased by one.
 */
- (OFNumber*)numberByDecreasing;
@end

Modified src/OFNumber.m from [818b4fcf27] to [5fe5542cc8].

863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
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
907
908
909
910
911
912
913
914
915
916
917

		return hash;
	default:
		return [self uInt32Value];
	}
}

- (OFNumber*)numberByAdding: (OFNumber*)num
{
	CALCULATE(+, num)
}

- (OFNumber*)numberBySubtracting: (OFNumber*)num
{
	CALCULATE(-, num)
}

- (OFNumber*)numberByMultiplyingWith: (OFNumber*)num
{
	CALCULATE(*, num)
}

- (OFNumber*)numberByDividingBy: (OFNumber*)num
{
	CALCULATE(/, num)
}

- (OFNumber*)numberByANDing: (OFNumber*)num
{
	CALCULATE2(&, num)
}

- (OFNumber*)numberByORing: (OFNumber*)num
{
	CALCULATE2(|, num)
}

- (OFNumber*)numberByXORing: (OFNumber*)num
{
	CALCULATE2(^, num)
}

- (OFNumber*)numberByShiftingLeftBy: (OFNumber*)num
{
	CALCULATE2(<<, num)
}

- (OFNumber*)numberByShiftingRightBy: (OFNumber*)num
{
	CALCULATE2(>>, num)
}

- (OFNumber*)numberByIncreasing
{
	CALCULATE3(+ 1)







|




|




|




|




|




|




|




|




|







863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
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
907
908
909
910
911
912
913
914
915
916
917

		return hash;
	default:
		return [self uInt32Value];
	}
}

- (OFNumber*)numberByAddingNumber: (OFNumber*)num
{
	CALCULATE(+, num)
}

- (OFNumber*)numberBySubtractingNumber: (OFNumber*)num
{
	CALCULATE(-, num)
}

- (OFNumber*)numberByMultiplyingWithNumber: (OFNumber*)num
{
	CALCULATE(*, num)
}

- (OFNumber*)numberByDividingWithNumber: (OFNumber*)num
{
	CALCULATE(/, num)
}

- (OFNumber*)numberByANDingWithNumber: (OFNumber*)num
{
	CALCULATE2(&, num)
}

- (OFNumber*)numberByORingWithNumber: (OFNumber*)num
{
	CALCULATE2(|, num)
}

- (OFNumber*)numberByXORingWithNumber: (OFNumber*)num
{
	CALCULATE2(^, num)
}

- (OFNumber*)numberByShiftingLeftWithNumber: (OFNumber*)num
{
	CALCULATE2(<<, num)
}

- (OFNumber*)numberByShiftingRightWithNumber: (OFNumber*)num
{
	CALCULATE2(>>, num)
}

- (OFNumber*)numberByIncreasing
{
	CALCULATE3(+ 1)

Modified tests/OFNumberTests.m from [6cf377110f] to [1bd462ec42].

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
	TEST(@"-[asDouble]", [num doubleValue] == 123456789.L)

	TEST(@"-[numberByDecreasing]",
	    [[num numberByDecreasing]
	    isEqual: [OFNumber numberWithInt32: 123456788]])

	TEST(@"-[numberByDividingBy:]",
	    [[num numberByDividingBy: [OFNumber numberWithInt: 2]] intValue] ==
	    61728394)

	TEST(@"-[numberByXORing:]",
	    [[num numberByXORing: [OFNumber numberWithInt: 123456831]]
	    intValue] == 42)

	TEST(@"-[numberByShiftingRightBy:]",
	    [[num numberByShiftingRightBy: [OFNumber numberWithInt: 8]]
	    intValue] == 482253)

	[pool drain];
}
@end







|
|


|



|





36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
	TEST(@"-[asDouble]", [num doubleValue] == 123456789.L)

	TEST(@"-[numberByDecreasing]",
	    [[num numberByDecreasing]
	    isEqual: [OFNumber numberWithInt32: 123456788]])

	TEST(@"-[numberByDividingBy:]",
	    [[num numberByDividingWithNumber: [OFNumber numberWithInt: 2]]
	    intValue] == 61728394)

	TEST(@"-[numberByXORing:]",
	    [[num numberByXORingWithNumber: [OFNumber numberWithInt: 123456831]]
	    intValue] == 42)

	TEST(@"-[numberByShiftingRightBy:]",
	    [[num numberByShiftingRightWithNumber: [OFNumber numberWithInt: 8]]
	    intValue] == 482253)

	[pool drain];
}
@end