ObjFW  Diff

Differences From Artifact [f20700cf69]:

To Artifact [e3d984f0cd]:


10
11
12
13
14
15
16

17
18
19
20
21
22
23
 */

#include "config.h"

#include <math.h>

#import "OFNumber.h"

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

#define RETURN_AS(t)							\
	switch (type) {							\
	case OF_NUMBER_BOOL:						\
		return (t)value.bool_;					\







>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 */

#include "config.h"

#include <math.h>

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

#define RETURN_AS(t)							\
	switch (type) {							\
	case OF_NUMBER_BOOL:						\
		return (t)value.bool_;					\
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
+ numberWithIntMax: (intmax_t)intmax
{
	return [[[self alloc] initWithIntMax: intmax] autorelease];
}

+ numberWithUIntMax: (uintmax_t)uintmax
{
	return [[[self alloc] initWithIntMax: uintmax] autorelease];
}

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








|







399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
+ numberWithIntMax: (intmax_t)intmax
{
	return [[[self alloc] initWithIntMax: intmax] autorelease];
}

+ numberWithUIntMax: (uintmax_t)uintmax
{
	return [[[self alloc] initWithUIntMax: uintmax] autorelease];
}

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

953
954
955
956
957
958
959


960
961
962
963
964
965
966
{
	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]];







>
>







954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
{
	CALCULATE3(- 1)
}

- (OFNumber*)remainderOfDivisionWithNumber: (OFNumber*)num
{
	switch (type) {
	case OF_NUMBER_BOOL:
		return [OFNumber numberWithBool: value.bool_ % [num boolValue]];
	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]];
1035
1036
1037
1038
1039
1040
1041







































1042
	}
}

- copy
{
	return [self retain];
}







































@end







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

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
	}
}

- copy
{
	return [self retain];
}

- (OFString*)description
{
	switch (type) {
	case OF_NUMBER_BOOL:
		return (value.bool_ ? @"YES" : @"NO");
	case OF_NUMBER_UCHAR:
	case OF_NUMBER_USHORT:
	case OF_NUMBER_UINT:
	case OF_NUMBER_ULONG:
	case OF_NUMBER_UINT8:
	case OF_NUMBER_UINT16:
	case OF_NUMBER_UINT32:
	case OF_NUMBER_UINT64:
	case OF_NUMBER_SIZE:
	case OF_NUMBER_UINTMAX:
	case OF_NUMBER_UINTPTR:
		return [OFString stringWithFormat: @"%ju", [self uIntMaxValue]];
	case OF_NUMBER_CHAR:
	case OF_NUMBER_SHORT:
	case OF_NUMBER_INT:
	case OF_NUMBER_LONG:
	case OF_NUMBER_INT8:
	case OF_NUMBER_INT16:
	case OF_NUMBER_INT32:
	case OF_NUMBER_INT64:
	case OF_NUMBER_SSIZE:
	case OF_NUMBER_INTMAX:
	case OF_NUMBER_PTRDIFF:
	case OF_NUMBER_INTPTR:
		return [OFString stringWithFormat: @"%jd", [self intMaxValue]];
	case OF_NUMBER_FLOAT:
		return [OFString stringWithFormat: @"%f", [self floatValue]];
	case OF_NUMBER_DOUBLE:
		return [OFString stringWithFormat: @"%lf", [self doubleValue]];
	default:
		@throw [OFInvalidFormatException newWithClass: isa];
	}
}
@end