Differences From Artifact [3bd254e0cf]:
- File
src/OFNumber.m
— part of check-in
[0db281bf03]
at
2012-06-11 11:08:47
on branch trunk
— Improve -[OFNumber description].
The %f conversion specifier does not include a decimal point if none is
required. In such cases, append ".0" to indicate that the number is of a
floating point type. (user: js, size: 28581) [annotate] [blame] [check-ins using] [more...]
To Artifact [b82d9f97c4]:
- File src/OFNumber.m — part of check-in [8892ae9fcc] at 2012-07-12 01:28:46 on branch trunk — Don't access isa directly. (user: js, size: 28702) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
82 83 84 85 86 87 88 | return (t)value.uintptr; \ case OF_NUMBER_FLOAT: \ return (t)value.float_; \ case OF_NUMBER_DOUBLE: \ return (t)value.double_; \ default: \ @throw [OFInvalidFormatException \ | | | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | return (t)value.uintptr; \ case OF_NUMBER_FLOAT: \ return (t)value.float_; \ case OF_NUMBER_DOUBLE: \ return (t)value.double_; \ default: \ @throw [OFInvalidFormatException \ exceptionWithClass: [self class]]; \ } #define CALCULATE(o, n) \ switch (type) { \ case OF_NUMBER_BOOL: \ return [OFNumber numberWithBool: \ value.bool_ o [n boolValue]]; \ case OF_NUMBER_CHAR: \ |
︙ | ︙ | |||
166 167 168 169 170 171 172 | return [OFNumber numberWithFloat: \ value.float_ o [n floatValue]]; \ case OF_NUMBER_DOUBLE: \ return [OFNumber numberWithDouble: \ value.double_ o [n doubleValue]]; \ default: \ @throw [OFInvalidFormatException \ | | | 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | return [OFNumber numberWithFloat: \ value.float_ o [n floatValue]]; \ case OF_NUMBER_DOUBLE: \ return [OFNumber numberWithDouble: \ value.double_ o [n doubleValue]]; \ default: \ @throw [OFInvalidFormatException \ exceptionWithClass: [self class]]; \ } #define CALCULATE2(o, n) \ switch (type) { \ case OF_NUMBER_BOOL: \ return [OFNumber numberWithBool: \ value.bool_ o [n boolValue]]; \ case OF_NUMBER_CHAR: \ |
︙ | ︙ | |||
245 246 247 248 249 250 251 | value.intptr o [n intPtrValue]]; \ case OF_NUMBER_UINTPTR: \ return [OFNumber numberWithUIntPtr: \ value.uintptr o [n uIntPtrValue]]; \ case OF_NUMBER_FLOAT: \ case OF_NUMBER_DOUBLE: \ @throw [OFNotImplementedException \ | | | | 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | value.intptr o [n intPtrValue]]; \ case OF_NUMBER_UINTPTR: \ return [OFNumber numberWithUIntPtr: \ value.uintptr o [n uIntPtrValue]]; \ case OF_NUMBER_FLOAT: \ case OF_NUMBER_DOUBLE: \ @throw [OFNotImplementedException \ exceptionWithClass: [self class] \ selector: _cmd]; \ default: \ @throw [OFInvalidFormatException \ exceptionWithClass: [self class]]; \ } #define CALCULATE3(o) \ switch (type) { \ case OF_NUMBER_BOOL: \ return [OFNumber numberWithBool: value.bool_ o]; \ case OF_NUMBER_CHAR: \ return [OFNumber numberWithChar: value.char_ o]; \ |
︙ | ︙ | |||
310 311 312 313 314 315 316 | return [OFNumber numberWithUIntPtr: value.uintptr o]; \ case OF_NUMBER_FLOAT: \ return [OFNumber numberWithFloat: value.float_ o]; \ case OF_NUMBER_DOUBLE: \ return [OFNumber numberWithDouble: value.double_ o]; \ default: \ @throw [OFInvalidFormatException \ | | | 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | return [OFNumber numberWithUIntPtr: value.uintptr o]; \ case OF_NUMBER_FLOAT: \ return [OFNumber numberWithFloat: value.float_ o]; \ case OF_NUMBER_DOUBLE: \ return [OFNumber numberWithDouble: value.double_ o]; \ default: \ @throw [OFInvalidFormatException \ exceptionWithClass: [self class]]; \ } @implementation OFNumber + numberWithBool: (BOOL)bool_ { return [[[self alloc] initWithBool: bool_] autorelease]; } |
︙ | ︙ | |||
446 447 448 449 450 451 452 | + numberWithDouble: (double)double_ { return [[[self alloc] initWithDouble: double_] autorelease]; } - init { | | | 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | + numberWithDouble: (double)double_ { return [[[self alloc] initWithDouble: double_] autorelease]; } - init { @throw [OFNotImplementedException exceptionWithClass: [self class] selector: _cmd]; } - initWithBool: (BOOL)bool_ { self = [super init]; |
︙ | ︙ | |||
721 722 723 724 725 726 727 | @try { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFString *typeString; if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException | | | | | 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 | @try { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFString *typeString; if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; typeString = [[element attributeForName: @"type"] stringValue]; if ([typeString isEqual: @"boolean"]) { type = OF_NUMBER_BOOL; if ([[element stringValue] isEqual: @"YES"]) value.bool_ = YES; else if ([[element stringValue] isEqual: @"NO"]) value.bool_ = NO; else @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; } else if ([typeString isEqual: @"unsigned"]) { /* * FIXME: This will fail if the value is bigger than * INTMAX_MAX! */ type = OF_NUMBER_UINTMAX; value.uintmax = [element decimalValue]; } else if ([typeString isEqual: @"signed"]) { type = OF_NUMBER_INTMAX; value.intmax = [element decimalValue]; } else if ([typeString isEqual: @"float"]) { type = OF_NUMBER_FLOAT; value.float_ = [element floatValue]; } else if ([typeString isEqual: @"double"]) { type = OF_NUMBER_DOUBLE; value.double_ = [element doubleValue]; } else @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; [pool release]; } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
1125 1126 1127 1128 1129 1130 1131 | case OF_NUMBER_FLOAT: return [OFNumber numberWithFloat: fmodf(value.float_, [number floatValue])]; case OF_NUMBER_DOUBLE: return [OFNumber numberWithDouble: fmod(value.double_, [number doubleValue])]; default: | | > | 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 | case OF_NUMBER_FLOAT: return [OFNumber numberWithFloat: fmodf(value.float_, [number floatValue])]; case OF_NUMBER_DOUBLE: return [OFNumber numberWithDouble: fmod(value.double_, [number doubleValue])]; default: @throw [OFInvalidFormatException exceptionWithClass: [self class]]; } } - copy { return [self retain]; } |
︙ | ︙ | |||
1185 1186 1187 1188 1189 1190 1191 | if (![ret containsString: @"."]) [ret appendString: @".0"]; [ret makeImmutable]; return ret; default: | | > | 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 | if (![ret containsString: @"."]) [ret appendString: @".0"]; [ret makeImmutable]; return ret; default: @throw [OFInvalidFormatException exceptionWithClass: [self class]]; } } - (OFXMLElement*)XMLElementBySerializing { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLElement *element; |
︙ | ︙ | |||
1247 1248 1249 1250 1251 1252 1253 | [element addAttributeWithName: @"type" stringValue: @"double"]; [element setStringValue: [OFString stringWithFormat: @"%la", value.double_]]; break; default: | | > | 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 | [element addAttributeWithName: @"type" stringValue: @"double"]; [element setStringValue: [OFString stringWithFormat: @"%la", value.double_]]; break; default: @throw [OFInvalidFormatException exceptionWithClass: [self class]]; } [element retain]; [pool release]; [element autorelease]; return element; |
︙ | ︙ |