summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--o3d/core/cross/math_utilities.cc11
-rw-r--r--o3d/core/cross/math_utilities.h6
-rw-r--r--o3d/import/cross/memory_stream_test.cc19
3 files changed, 20 insertions, 16 deletions
diff --git a/o3d/core/cross/math_utilities.cc b/o3d/core/cross/math_utilities.cc
index c91e7fb..fd3f498 100644
--- a/o3d/core/cross/math_utilities.cc
+++ b/o3d/core/cross/math_utilities.cc
@@ -161,7 +161,6 @@ uint16 FloatToHalf(float value) {
}
float HalfToFloat(uint16 half) {
- unsigned int value;
unsigned int sign = static_cast<unsigned int>(half >> 15);
unsigned int mantissa = static_cast<unsigned int>(half & ((1 << 10) - 1));
unsigned int exponent = static_cast<unsigned int>(
@@ -198,8 +197,12 @@ float HalfToFloat(uint16 half) {
exponent = (exponent << 13) + kHalfFloatMinBiasedExpAsSingleFpExponent;
}
- value = (sign << 31) | exponent | mantissa;
- return *((float *)&value);
+ union {
+ unsigned int int_value;
+ float float_value;
+ } value;
+ value.int_value = (sign << 31) | exponent | mantissa;
+ return value.float_value;
}
} // namespace Vectormath
@@ -225,4 +228,6 @@ float FrobeniusNorm(const Matrix4& matrix) {
}
return sqrtf(sumOfElementsSquared);
}
+
+const float kPi = ::acosf(-1.0f);
} // namespace o3d
diff --git a/o3d/core/cross/math_utilities.h b/o3d/core/cross/math_utilities.h
index c4ee147..4ba556e 100644
--- a/o3d/core/cross/math_utilities.h
+++ b/o3d/core/cross/math_utilities.h
@@ -79,11 +79,7 @@ float FrobeniusNorm(const Matrix3& matrix);
// See http://en.wikipedia.org/wiki/Matrix_norm
float FrobeniusNorm(const Matrix4& matrix);
-const float kPi = acosf(-1.0f);
+extern const float kPi;
} // namespace o3d
#endif // O3D_CORE_CROSS_MATH_UTILITIES_H_
-
-
-
-
diff --git a/o3d/import/cross/memory_stream_test.cc b/o3d/import/cross/memory_stream_test.cc
index f72d7f0..3b238fe 100644
--- a/o3d/import/cross/memory_stream_test.cc
+++ b/o3d/import/cross/memory_stream_test.cc
@@ -239,16 +239,19 @@ TEST_F(MemoryStreamTest, EndianSanityFloat32) {
uint8 *p8 = reinterpret_cast<uint8*>(p);
MemoryWriteStream write_stream(p8, sizeof(int32) * 2);
- float value = 3.14159f;
- write_stream.WriteLittleEndianFloat32(value);
- write_stream.WriteBigEndianFloat32(value);
+ union {
+ int32 ivalue;
+ float fvalue;
+ } value;
+ value.fvalue = 3.14159f;
+ write_stream.WriteLittleEndianFloat32(value.fvalue);
+ write_stream.WriteBigEndianFloat32(value.fvalue);
// Verify that the bytes are in the correct order
- int32 ivalue = *reinterpret_cast<int32*>(&value); // interpret float as int32
- uint8 byte1 = ivalue & 0xff;
- uint8 byte2 = (ivalue >> 8) & 0xff;
- uint8 byte3 = (ivalue >> 16) & 0xff;
- uint8 byte4 = (ivalue >> 24) & 0xff;
+ uint8 byte1 = value.ivalue & 0xff;
+ uint8 byte2 = (value.ivalue >> 8) & 0xff;
+ uint8 byte3 = (value.ivalue >> 16) & 0xff;
+ uint8 byte4 = (value.ivalue >> 24) & 0xff;
// validate little-endian
EXPECT_EQ(byte1, p8[0]);