ObjFW  Check-in [8fd09d2c59]

Overview
Comment:Add -[remainderOfDivisionWithNumber:] to OFNumber.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8fd09d2c59da427d9e1aa7ebf53c2f12e17bf8626a7b097e579c94fab56f1cfd
User & Date: js on 2010-05-13 17:11:57
Other Links: manifest | tags
Context
2010-05-13
18:27
Better handling of \n and \r in OFXMLParser. check-in: 7aa0a50f2f user: js tags: trunk
17:11
Add -[remainderOfDivisionWithNumber:] to OFNumber. check-in: 8fd09d2c59 user: js tags: trunk
2010-05-09
14:47
Added tag 0.3-release for changeset 50132ecbe6a2 check-in: 1e5b519dbf user: js tags: trunk
Changes

Modified src/OFNumber.h from [fefd022278] to [6d290d5b08].

640
641
642
643
644
645
646






647
 */
- (OFNumber*)numberByIncreasing;

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






@end







>
>
>
>
>
>

640
641
642
643
644
645
646
647
648
649
650
651
652
653
 */
- (OFNumber*)numberByIncreasing;

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

/**
 * \param num The number to divide by
 * \return The remainder of a division by the specified number
 */
- (OFNumber*)remainderOfDivisionWithNumber: (OFNumber*)num;
@end

Modified src/OFNumber.m from [5fe5542cc8] to [8047d2e395].

1
2
3
4
5
6
7
8
9
10
11
12


13
14
15
16
17
18
19
/*
 * Copyright (c) 2008 - 2010
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"



#import "OFNumber.h"
#import "OFExceptions.h"
#import "macros.h"

#define RETURN_AS(t)							\
	switch (type) {							\












>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * Copyright (c) 2008 - 2010
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#include <math.h>

#import "OFNumber.h"
#import "OFExceptions.h"
#import "macros.h"

#define RETURN_AS(t)							\
	switch (type) {							\
917
918
919
920
921
922
923

















































































924
	CALCULATE3(+ 1)
}

- (OFNumber*)numberByDecreasing
{
	CALCULATE3(- 1)
}

















































































@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
	CALCULATE3(+ 1)
}

- (OFNumber*)numberByDecreasing
{
	CALCULATE3(- 1)
}

- (OFNumber*)remainderOfDivisionWithNumber: (OFNumber*)num
{
	switch (type) {
	case OF_NUMBER_CHAR:
		return [OFNumber numberWithChar: value.char_ % [num charValue]];
	case OF_NUMBER_SHORT:
		return [OFNumber numberWithShort:
		    value.short_ % [num shortValue]];
	case OF_NUMBER_INT:
		return [OFNumber numberWithInt: value.int_ % [num intValue]];
	case OF_NUMBER_LONG:
		return [OFNumber numberWithLong:
		    value.long_ % [num longValue]];
	case OF_NUMBER_UCHAR:
		return [OFNumber numberWithUnsignedChar:
		    value.uchar % [num unsignedCharValue]];
	case OF_NUMBER_USHORT:
		return [OFNumber numberWithUnsignedShort:
		    value.ushort % [num unsignedShortValue]];
	case OF_NUMBER_UINT:
		return [OFNumber numberWithUnsignedInt:
		    value.uint % [num unsignedIntValue]];
	case OF_NUMBER_ULONG:
		return [OFNumber numberWithUnsignedLong:
		    value.ulong % [num unsignedLongValue]];
	case OF_NUMBER_INT8:
		return [OFNumber numberWithInt8:
		    value.int8 % [num int8Value]];
	case OF_NUMBER_INT16:
		return [OFNumber numberWithInt16:
		    value.int16 % [num int16Value]];
	case OF_NUMBER_INT32:
		return [OFNumber numberWithInt32:
		    value.int32 % [num int32Value]];
	case OF_NUMBER_INT64:
		return [OFNumber numberWithInt64:
		    value.int64 % [num int64Value]];
	case OF_NUMBER_UINT8:
		return [OFNumber numberWithUInt8:
		    value.uint8 % [num uInt8Value]];
	case OF_NUMBER_UINT16:
		return [OFNumber numberWithUInt16:
		    value.uint16 % [num uInt16Value]];
	case OF_NUMBER_UINT32:
		return [OFNumber numberWithUInt32:
		    value.uint32 % [num uInt32Value]];
	case OF_NUMBER_UINT64:
		return [OFNumber numberWithUInt64:
		    value.uint64 % [num uInt64Value]];
	case OF_NUMBER_SIZE:
		return [OFNumber numberWithSize:
		    value.size % [num sizeValue]];
	case OF_NUMBER_SSIZE:
		return [OFNumber numberWithSSize:
		    value.ssize % [num sSizeValue]];
	case OF_NUMBER_INTMAX:
		return [OFNumber numberWithIntMax:
		    value.intmax % [num intMaxValue]];
	case OF_NUMBER_UINTMAX:
		return [OFNumber numberWithUIntMax:
		    value.uintmax % [num uIntMaxValue]];
	case OF_NUMBER_PTRDIFF:
		return [OFNumber numberWithPtrDiff:
		    value.ptrdiff % [num ptrDiffValue]];
	case OF_NUMBER_INTPTR:
		return [OFNumber numberWithIntPtr:
		    value.intptr % [num intPtrValue]];
	case OF_NUMBER_UINTPTR:
		return [OFNumber numberWithUIntPtr:
		    value.uintptr % [num uIntPtrValue]];
	case OF_NUMBER_FLOAT:
		return [OFNumber
		    numberWithFloat: fmodf(value.float_, [num floatValue])];
	case OF_NUMBER_DOUBLE:
		return [OFNumber
		    numberWithDouble: fmod(value.double_, [num doubleValue])];
	default:
		@throw [OFInvalidFormatException newWithClass: isa];
	}
}
@end

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

46
47
48
49
50
51
52




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

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





	[pool drain];
}
@end







>
>
>
>




46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
	TEST(@"-[numberByXORing:]",
	    [[num numberByXORingWithNumber: [OFNumber numberWithInt: 123456831]]
	    intValue] == 42)

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

	TEST(@"-[remainderOfDivisionWithNumber:]",
	    [[num remainderOfDivisionWithNumber: [OFNumber numberWithInt: 11]]
	    intValue] == 5)

	[pool drain];
}
@end