ObjFW  Check-in [ac2714dd86]

Overview
Comment:Serialize floats and doubles in a format that does not lose precision.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ac2714dd86e91a7b557902389a06f989b9b2f47b58b3d80d1e3e0cb95de216cd
User & Date: js on 2011-06-05 21:26:21
Other Links: manifest | tags
Context
2011-06-05
22:26
Nicer API for serialization. check-in: 29988c434b user: js tags: trunk
21:26
Serialize floats and doubles in a format that does not lose precision. check-in: ac2714dd86 user: js tags: trunk
20:45
Add -[stringByPrependingString:] to OFString. check-in: 5b7d19e956 user: js tags: trunk
Changes

Modified src/OFNumber.m from [bbca96f8b9] to [d98652159e].

744
745
746
747
748
749
750

751
752
753

754
755
756
757
758
759
760
761
			type = OF_NUMBER_UINTMAX;
			value.uintmax = [[element stringValue] decimalValue];
		} else if ([typeString isEqual: @"signed"]) {
			type = OF_NUMBER_INTMAX;
			value.intmax = [[element stringValue] decimalValue];
		} else if ([typeString isEqual: @"float"]) {
			type = OF_NUMBER_FLOAT;

			value.float_ = [[element stringValue] floatValue];
		} else if ([typeString isEqual: @"double"]) {
			type = OF_NUMBER_DOUBLE;

			value.double_ = [[element stringValue] doubleValue];
		} else
			@throw [OFInvalidArgumentException newWithClass: isa
							       selector: _cmd];

		[pool release];
	} @catch (id e) {
		[self release];







>
|


>
|







744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
			type = OF_NUMBER_UINTMAX;
			value.uintmax = [[element stringValue] decimalValue];
		} else if ([typeString isEqual: @"signed"]) {
			type = OF_NUMBER_INTMAX;
			value.intmax = [[element stringValue] decimalValue];
		} else if ([typeString isEqual: @"float"]) {
			type = OF_NUMBER_FLOAT;
			*(uint32_t*)&value.float_ =
			    (uint32_t)[[element stringValue] hexadecimalValue];
		} else if ([typeString isEqual: @"double"]) {
			type = OF_NUMBER_DOUBLE;
			*(uint64_t*)&value.double_ =
			    (uint64_t)[[element stringValue] hexadecimalValue];
		} else
			@throw [OFInvalidArgumentException newWithClass: isa
							       selector: _cmd];

		[pool release];
	} @catch (id e) {
		[self release];
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214



1215
1216
1217
1218



1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
	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:
		[element addAttributeWithName: @"type"
				  stringValue: @"signed"];
		break;
	case OF_NUMBER_FLOAT:
		[element addAttributeWithName: @"type"
				  stringValue: @"float"];



		break;
	case OF_NUMBER_DOUBLE:
		[element addAttributeWithName: @"type"
				  stringValue: @"double"];



		break;
	default:
		@throw [OFInvalidFormatException newWithClass: isa];
	}

	[pool release];

	return element;
}
@end







|






>
>
>




>
>
>










1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
	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:;
		[element addAttributeWithName: @"type"
				  stringValue: @"signed"];
		break;
	case OF_NUMBER_FLOAT:
		[element addAttributeWithName: @"type"
				  stringValue: @"float"];
		[element setStringValue:
		    [OFString stringWithFormat: @"%" PRIX32,
						*(uint32_t*)&value.float_]];
		break;
	case OF_NUMBER_DOUBLE:
		[element addAttributeWithName: @"type"
				  stringValue: @"double"];
		[element setStringValue:
		    [OFString stringWithFormat: @"%" PRIX64,
						*(uint64_t*)&value.double_]];
		break;
	default:
		@throw [OFInvalidFormatException newWithClass: isa];
	}

	[pool release];

	return element;
}
@end