1
0

Be more parinoid about int sizes

This commit is contained in:
Tycho 2014-03-09 11:47:22 -07:00
parent 9825dbfd34
commit 1bf99b5fd2
3 changed files with 18 additions and 5 deletions

View File

@ -2,6 +2,7 @@
#pragma once #pragma once
#include "ChatColor.h" #include "ChatColor.h"
#include <limits>
@ -469,7 +470,7 @@ inline void EulerToVector(double a_Pan, double a_Pitch, double & a_X, double & a
inline void VectorToEuler(double a_X, double a_Y, double a_Z, double & a_Pan, double & a_Pitch) inline void VectorToEuler(double a_X, double a_Y, double a_Z, double & a_Pan, double & a_Pitch)
{ {
if (fabs(a_X) < std::numeric_limits::epsilon() ) if (fabs(a_X) < std::numeric_limits<double>::epsilon())
{ {
a_Pan = atan2(a_Z, a_X) * 180 / PI - 90; a_Pan = atan2(a_Z, a_X) * 180 / PI - 90;
} }

View File

@ -81,7 +81,7 @@
#endif #endif
#include <stddef.h>
// Integral types with predefined sizes: // Integral types with predefined sizes:
@ -96,8 +96,22 @@ typedef unsigned short UInt16;
typedef unsigned char Byte; typedef unsigned char Byte;
// If you get an error about specialization check the size of integral types
template <typename T, size_t Size, bool x = sizeof(T) == Size>
class SizeChecker;
template <typename T, size_t Size>
class SizeChecker<T, Size, true> {
T v;
};
template class SizeChecker<Int64, 8>;
template class SizeChecker<Int32, 4>;
template class SizeChecker<Int16, 2>;
template class SizeChecker<UInt64, 8>;
template class SizeChecker<UInt32, 4>;
template class SizeChecker<UInt16, 2>;
// A macro to disallow the copy constructor and operator= functions // A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for any class that shouldn't allow copying itself // This should be used in the private: declarations for any class that shouldn't allow copying itself
@ -179,7 +193,7 @@ typedef unsigned char Byte;
#include <memory> #include <memory>
#include <set> #include <set>
#include <queue> #include <queue>
#include <limits>

View File

@ -59,8 +59,6 @@
#include <ctime> #include <ctime>
#include <cmath> #include <cmath>
#include "Globals.h"
class MTRand { class MTRand {
// Data // Data
public: public: