|
@@ -342,28 +342,52 @@ float cmMidiToHz( unsigned midi )
|
342
|
342
|
|
343
|
343
|
//=================================================================
|
344
|
344
|
// Floating point byte swapping
|
|
345
|
+
|
|
346
|
+// Unions used to type-pun the swapping functions and thereby
|
|
347
|
+// avoid strict aliasing problems with -O2. Using unions for
|
|
348
|
+// this purpose is apparently legal under C99 but not C++.
|
|
349
|
+
|
|
350
|
+typedef union
|
|
351
|
+{
|
|
352
|
+ unsigned u;
|
|
353
|
+ float f;
|
|
354
|
+} _cmMathU_t;
|
|
355
|
+
|
|
356
|
+typedef union
|
|
357
|
+{
|
|
358
|
+ unsigned long long u;
|
|
359
|
+ double f;
|
|
360
|
+} _cmMathUL_t;
|
|
361
|
+
|
345
|
362
|
unsigned cmFfSwapFloatToUInt( float v )
|
346
|
363
|
{
|
347
|
364
|
assert( sizeof(float) == sizeof(unsigned));
|
348
|
|
- return cmSwap32(*(unsigned*)&v);
|
|
365
|
+ _cmMathU_t u;
|
|
366
|
+ u.f=v;
|
|
367
|
+ return cmSwap32(u.u);
|
349
|
368
|
}
|
350
|
369
|
|
351
|
370
|
float cmFfSwapUIntToFloat( unsigned v )
|
352
|
371
|
{
|
353
|
372
|
assert( sizeof(float) == sizeof(unsigned));
|
354
|
|
- v = cmSwap32(v);
|
355
|
|
- return *((float*)&v);
|
|
373
|
+ _cmMathU_t u;
|
|
374
|
+
|
|
375
|
+ u.u = cmSwap32(v);
|
|
376
|
+ return u.f;
|
356
|
377
|
}
|
357
|
378
|
|
358
|
379
|
unsigned long long cmFfSwapDoubleToULLong( double v )
|
359
|
380
|
{
|
360
|
381
|
assert( sizeof(double) == sizeof(unsigned long long));
|
361
|
|
- return cmSwap64(*(unsigned long long*)&v);
|
|
382
|
+ _cmMathUL_t u;
|
|
383
|
+ u.f = v;
|
|
384
|
+ return cmSwap64(u.u);
|
362
|
385
|
}
|
363
|
386
|
|
364
|
387
|
double cmFfSwapULLongToDouble( unsigned long long v )
|
365
|
388
|
{
|
366
|
389
|
assert( sizeof(double) == sizeof(unsigned long long));
|
367
|
|
- v = cmSwap64(v);
|
368
|
|
- return *((double*)&v);
|
|
390
|
+ _cmMathUL_t u;
|
|
391
|
+ u.u = cmSwap64(v);
|
|
392
|
+ return u.f;
|
369
|
393
|
}
|