ObjFW  Diff

Differences From Artifact [b82d9f97c4]:

To Artifact [b7208d53f6]:

  • File src/OFNumber.m — part of check-in [a6ee2b2065] at 2012-07-31 12:05:46 on branch trunk — Slightly changed serialization format.

    printf's %a was too fragile to serialize floats and doubles, as it was
    behaving differently on different OSes and OS versions. Instead, a hex
    representation of the float/double in big endian is used now. While this
    is less readable, it is guaranteed to be accurate and always the same. (user: js, size: 29087) [annotate] [blame] [check-ins using]


748
749
750
751
752
753
754







755
756

757







758
759

760
761
762
763
764
765
766
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762

763
764
765
766
767
768
769
770
771
772

773
774
775
776
777
778
779
780







+
+
+
+
+
+
+

-
+

+
+
+
+
+
+
+

-
+







			 */
			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"]) {
			union {
				float f;
				uint32_t u;
			} f;

			f.u = (uint32_t)[element hexadecimalValue];

			type = OF_NUMBER_FLOAT;
			value.float_ = [element floatValue];
			value.float_ = of_bswap_float_if_le(f.f);
		} else if ([typeString isEqual: @"double"]) {
			union {
				double d;
				uint64_t u;
			} d;

			d.u = (uint64_t)[element hexadecimalValue];

			type = OF_NUMBER_DOUBLE;
			value.double_ = [element doubleValue];
			value.double_ = of_bswap_double_if_le(d.d);
		} else
			@throw [OFInvalidArgumentException
			    exceptionWithClass: [self class]
				      selector: _cmd];

		[pool release];
	} @catch (id e) {
1235
1236
1237
1238
1239
1240
1241







1242
1243
1244
1245

1246
1247
1248







1249
1250
1251
1252

1253
1254
1255
1256
1257
1258
1259
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265

1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279

1280
1281
1282
1283
1284
1285
1286
1287







+
+
+
+
+
+
+



-
+



+
+
+
+
+
+
+



-
+







	case OF_NUMBER_INTMAX:
	case OF_NUMBER_PTRDIFF:
	case OF_NUMBER_INTPTR:;
		[element addAttributeWithName: @"type"
				  stringValue: @"signed"];
		break;
	case OF_NUMBER_FLOAT:;
		union {
			float f;
			uint32_t u;
		} f;

		f.f = of_bswap_float_if_le(value.float_);

		[element addAttributeWithName: @"type"
				  stringValue: @"float"];
		[element setStringValue:
		    [OFString stringWithFormat: @"%a", value.float_]];
		    [OFString stringWithFormat: @"%08" PRIx32, f.u]];

		break;
	case OF_NUMBER_DOUBLE:;
		union {
			double d;
			uint64_t u;
		} d;

		d.d = of_bswap_double_if_le(value.double_);

		[element addAttributeWithName: @"type"
				  stringValue: @"double"];
		[element setStringValue:
		    [OFString stringWithFormat: @"%la", value.double_]];
		    [OFString stringWithFormat: @"%016" PRIx64, d.u]];

		break;
	default:
		@throw [OFInvalidFormatException
		    exceptionWithClass: [self class]];
	}