ObjFW  Check-in [4b8e8836c8]

Overview
Comment:Always use unions to access a float as a uint32_t.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4b8e8836c8457aa740d8490d5f1c8f9f16f393fa5694c2dc27301e167eceb02c
User & Date: js on 2011-06-06 03:19:30
Other Links: manifest | tags
Context
2011-06-06
13:34
Fix float*/uint32_t* casts forgotten in the last commit. check-in: b507c330f5 user: js tags: trunk
03:19
Always use unions to access a float as a uint32_t. check-in: 4b8e8836c8 user: js tags: trunk
00:46
Don't let a comment prevent indentation and indent comments correctly. check-in: ddc9f8ac04 user: js tags: trunk
Changes

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

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







|
>
>
>
>
>
>
>



|
|

|
>
>
>
>
>
>
>



|
|










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
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
	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:;
		union {
			float f;
			uint32_t i;
		} f;

		f.f = value.float_;

		[element addAttributeWithName: @"type"
				  stringValue: @"float"];
		[element setStringValue:
		    [OFString stringWithFormat: @"%" PRIX32, f.i]];

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

		d.d = value.double_;

		[element addAttributeWithName: @"type"
				  stringValue: @"double"];
		[element setStringValue:
		    [OFString stringWithFormat: @"%" PRIX64, d.i]];

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

	[pool release];

	return element;
}
@end

Modified src/macros.h from [793bb737f0] to [9c903dee26].

206
207
208
209
210
211
212


213





214
215
216
217
218
219


220





221
222
223
224
225
226
227
228
# define of_bswap32(i) of_bswap32_const(i)
# define of_bswap64(i) of_bswap64_const(i)
#endif

static OF_INLINE float OF_CONST_FUNC
of_bswap_float(float f)
{


	uint32_t tmp = of_bswap32(*(uint32_t*)&f);





	return *(float*)&tmp;
}

static OF_INLINE double OF_CONST_FUNC
of_bswap_double(double d)
{


	uint64_t tmp = of_bswap64(*(uint64_t*)&d);





	return *(double*)&tmp;
}

static OF_INLINE void
of_bswap32_vec(uint32_t *buffer, size_t length)
{
	while (length--) {
		*buffer = of_bswap32(*buffer);







>
>
|
>
>
>
>
>
|





>
>
|
>
>
>
>
>
|







206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# define of_bswap32(i) of_bswap32_const(i)
# define of_bswap64(i) of_bswap64_const(i)
#endif

static OF_INLINE float OF_CONST_FUNC
of_bswap_float(float f)
{
	union {
		float f;
		uint32_t i;
	} u;

	u.f = f;
	u.i = of_bswap32(u.i);

	return u.f;
}

static OF_INLINE double OF_CONST_FUNC
of_bswap_double(double d)
{
	union {
		double d;
		uint64_t i;
	} u;

	u.d = d;
	u.i = of_bswap64(u.i);

	return u.d;
}

static OF_INLINE void
of_bswap32_vec(uint32_t *buffer, size_t length)
{
	while (length--) {
		*buffer = of_bswap32(*buffer);